Docker MySQL - You must set environment variables but it is set already

I've set the ENV variables but still container throws error that I should set them.

This is the image I'm trying to use: mysql-56-centos7.

Any suggestion on how to fix this?

Dockerfile:

FROM centos/mysql-56-centos7


ENV MYSQL_USER=root \
    MYSQL_PASSWORD=test \
    MYSQL_DATABASE=test \
    MYSQL_DATA_DIR=/var/lib/mysql \
    MYSQL_RUN_DIR=/run/mysqld \
    MYSQL_LOG_DIR=/var/log/mysql

EXPOSE 3306/tcp

CMD ["run-mysqld"]

Following is the error:

[root@centos1 test01]# docker container logs cf0245546d47
=> sourcing 20-validate-variables.sh ...
You must either specify the following environment variables:
  MYSQL_USER (regex: '^[a-zA-Z0-9_]+$')
  MYSQL_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$')
  MYSQL_DATABASE (regex: '^[a-zA-Z0-9_]+$')
Or the following environment variable:
  MYSQL_ROOT_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$')
Or both.
Optional Settings:
  MYSQL_LOWER_CASE_TABLE_NAMES (default: 0)
  MYSQL_LOG_QUERIES_ENABLED (default: 0)
  MYSQL_MAX_CONNECTIONS (default: 151)
  MYSQL_FT_MIN_WORD_LEN (default: 4)
  MYSQL_FT_MAX_WORD_LEN (default: 20)
  MYSQL_AIO (default: 1)
  MYSQL_KEY_BUFFER_SIZE (default: 32M or 10% of available memory)
  MYSQL_MAX_ALLOWED_PACKET (default: 200M)
  MYSQL_TABLE_OPEN_CACHE (default: 400)
  MYSQL_SORT_BUFFER_SIZE (default: 256K)
  MYSQL_READ_BUFFER_SIZE (default: 8M or 5% of available memory)
  MYSQL_INNODB_BUFFER_POOL_SIZE (default: 32M or 50% of available memory)
  MYSQL_INNODB_LOG_FILE_SIZE (default: 8M or 15% of available memory)
  MYSQL_INNODB_LOG_BUFFER_SIZE (default: 8M or 15% of available memory)

Solution 1:

To cut it short, you cannot run this image as root. In most cases, it is a bad practice to run any docker image as root.

Try to run as a different user, and you will be able to run the image.

For further details, I would just refer you to this discussion. Also if uncertain, always try to just use the default configuration that you can find on dockerhub.

Note: This is an outdated image, you should use something more up to date. This image hasn't been updated in over 3 years.