Search code examples
mysqldockerdocker-composedockerfiledocker-volume

Mysql docker container keeps restarting


The Container keeps restarting. I tried

  • docker-compose down -v
  • docker volume rm

The container was working fine earlier.

Logs

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.

2021-03-27 13:16:08+00:00 [ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user

Remove MYSQL_USER="root" and use one of the following to control the root user password:

- MYSQL_ROOT_PASSWORD

- MYSQL_ALLOW_EMPTY_PASSWORD

- MYSQL_RANDOM_ROOT_PASSWORD

Docker-compose.yml

 mysql:
    image: mysql:8.0
    ports:
      - 3306:3306
    expose:
      - "3306"
    cap_add:
      - SYS_NICE # CAP_SYS_NICE
    volumes:
      - ./cache/mysql:/var/lib/mysql
      - ./conf-mysql.cnf:/etc/mysql/conf.d/mysql.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_PASSWORD=root
      - MYSQL_USER=root
      - MYSQL_DATABASE=mydb
    restart: unless-stopped

Solution

  • Simply remove the MYSQL_USER and it will work fine because the root user gets created automatically.

    PS. This seems to be a problem with a newer docker version because this used to work before and not throw an error.