My.cnf files located incorrectly with MySQL 5.7 Docker Image

According to the link: Docker Hub under section Using a custom MySQL Configuration File, I should be able to startup MySQL with some custom configurations. I have added the following configs to my my.cnf file to enable bin logging.

[mysqld]
performance_schema=ON
server-id=223344
log_bin=mysql-bin
binlog_format=ROW
binlog_row_image=FULL

My folder structure is the following.

user
|- docker-compose.yml
|- mysql-config
   |- my.cnf
...

Then, I have the following docker-compose specification for MySQL.

version: '3'
services:
  mysqldb:
    image: mysql:5.7
    container_name: db_mysql
    command: ["--server-id=223344", "--log_bin=mysql-bin"]
    ports:
      - '3306:3306'
    environment:
      - MYSQL_ROOT_HOST=${DB_HOST}
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}  
      - MYSQL_USER=${DB_USER}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_DATABASE=${DB_NAME}
    volumes:
      - database_mysql:/var/lib/mysql
      - mysql-config:/etc/mysql/conf.d
    networks:
      - user

volumes:
  ...
  mysql-config:

When I run the MySQL service, I cannot find the my.cnf file that should have been mounted on /etc/mysql/conf.d/my.cnf for some reason. Furthermore, the my.cnf file is located at /etc/my.cnf instead of /etc/mysql/my.cnf as mentioned in the doc.

Could someone please let me know how I can mount the file correctly so my MySQL starts with the configs listed above?

If you don’t start the source path with “./” (relative path) or “/” (absolute path), you will create a volume. You want a bind mount. A volume will create a folder automatically under the docker data root and mount that. If you run

docker volume ls

you will find the created volume there.

This should work:

    volumes:
      - database_mysql:/var/lib/mysql
      - ./mysql-config:/etc/mysql/conf.d

Depending on how you want to store mysql data, you can change the source to a relative path, but I guess you don’t want that since you don’t have a fodler in your project.

Hey. This worked! Thanks, I just read about bind mounts and volumes more thoroughly in the Docker documentation. Thank you for helping me out.