Database, Docker, MySQL

Docker – MySQL 8 – mbind : operation not permitted

Docker – MySQL 8 – mbind : operation not permitted

My blog was down for few hours recently and I noticed that the database was down again. When I checked the Docker logs, I saw several errors like this:

mbind: Operation not permitted

My MySQL database is run through a docker container. I have recently upgraded to version 8 since I’m curious on what’s new. I searched about the error that I’m getting and it turns out to be a common error for MySQL version 8 among Docker users. It seems related to memory allocation of some sort.

Since I’m a Docker user, I used one of the solution from the MySQL docker library GitHub issue. The fix I used is by adding cap_add: [ SYS_NICE ] into docker-compose.yaml then rebuild and redeploy the container. Below is my full configuration.

# docker-compose.yaml
version: '3.9'
services:
  db:
    image: mysql:8.0.33-debian
    command: --default-authentication-plugin=mysql_native_password
    cap_add: [ SYS_NICE ]
    ports:
      - "${PORT_MAPPING}"
    environment:
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
    volumes:
      - type: volume
        source: data
        target: /var/lib/mysql
        volume:
          nocopy: true
    networks:
      - localnet
volumes:
  data:
networks:
  localnet:
    driver: bridge

Before I apply the changes, I need to backup the database so I just run my daily backup script. Next, I need to remove the containers and the images.

docker compose down
docker images
docker rmi <image id>

Running docker compose down without the -v option allows us to retain the volumes, in this case, the volume that holds my current database. This way, we can recreate the container and re-attach the volume back. I applied the change in docker-compose.yaml then recreate the image/containers again.

docker compose up -d

After this, my database is up and running and my data is still there. Running the backup script is just in case I lose the volumes.

You can view the MySQL docker setup here: https://github.com/lysender/docker-mysql-shared

Featured image by Kaique Rocha.