Reputation: 299
I'm using the default mysql image as one container in a multi-container app with docker compose. I've recently started seeing a periodic message get logged every second. The message is:
[Note] Access denied for user 'root'@'localhost' (using password: NO)
and is preceded by a timestamp. The service configuration in docker-compose.yml is as follows:
image: "mysql:5.7.18"
command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --port=$MYSQL_CONTAINER_PORT]
expose:
- "${MYSQL_CONTAINER_PORT}"
volumes:
- ${MYSQL_DATA}:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
ports:
- "${MYSQL_HOST_PORT}:${MYSQL_CONTAINER_PORT}"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 5s
retries: 10
I'm intentionally setting a root password when building the container image, and the application is able to access the database just fine via the username and password that I'm setting via the environment section.
There is nothing in my app that should be trying to access the mysql image as root, any thoughts on how I might figure out the source of these attempts to log in as root without a password?
If it helps, the docker-compose.yml file is set to version 2.1. The other two containers are (1) a flask app, and (2) an nginx web server that is also a proxy server for the app.
Upvotes: 3
Views: 1946
Reputation: 1705
Your problem is in the healthcheck command, Docker try to execute the command with root user without password:
image: "mysql:5.7.18"
command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --port=$MYSQL_CONTAINER_PORT]
expose:
- "${MYSQL_CONTAINER_PORT}"
volumes:
- ${MYSQL_DATA}:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
ports:
- "${MYSQL_HOST_PORT}:${MYSQL_CONTAINER_PORT}"
healthcheck:
test: ["CMD", "mysqladmin", "-u$MYSQL_USER", "-p$MYSQL_PASSWORD", "ping", "-h", "localhost"]
timeout: 5s
retries: 10
Upvotes: 4