The Container keeps restarting. I tried
The container was working fine until my pc got accidentally shutdown.
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
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
User root is reserved and already created with mysql when it's up.
MYSQL_USER must be a different name, not root.
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.
There was recent change how the official mysql docker which caused this issue. For further details you can check this PR on github.
For a quick solution you should remove MYSQL_USER=root and your docker-compose.yaml file should look something like this
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_DATABASE=mydb
restart: unless-stopped
I faced the exact same problem and here is how I fixed it.
Go to your docker-compose.yml file and make the following changes:
"MYSQL_USER: root" to "MYSQL_ROOT_USER: root" then delete the previous one.
"MYSQL_PASSWORD: YourPasseord" to "MYSQL_ROOT_PASSWORD: YourPasseord" then delete the previous one.
Example:Here is my configuration...
database_server:
image: mysql:8.0
container_name: mysql
restart: always
environment:
MYSQL_DATABASE: DB_epraca
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: Password
MYSQL_ROOT_HOST: localhost
Only update your the .env file:
DB_USERNAME=sail
DB_PASSWORD=password