Docker Community Forums

Share and learn in the Docker community.

Unable to mount MySQL configuration file on Windows

I want to set up a MySQL environment using Docker desktop for Windows.

I want to mount my.cnf by volumes in docker-compose.yml, but my.cnf is not copied to docker.

I checked various websites and found that on Windows, I need to grant permissions to the copied my.cnf, but that doesn’t work either.
(In the first place, my.cnf is not created in docker.

Is there any way to solve this problem?
Any advice would be appreciated in advance.

Just in case, here is my docker configuration file.

  • docker-compose.yml
version: '2'
services:

... snip ...

  db:
    image: mysql:8.0
    build:
      context: ./
      dockerfile: ./mysql/dockerfile
    container_name: my_container
    environment:
      MYSQL_ROOT_PASSWORD: {password}
      MYSQL_DATABASE: my_db
      command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    volumes:
      - './mysql/data:/var/lib/mysql'
      - './mysql/logs:/var/log/mysql'
      - './mysql/init:/docker-entrypoint-initdb.d'
      - './mysql/my.cnf:/etc/mysql/my.cnf'
    ports:
      - '3306:3306'
  • ./mysql/my.cnf
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_bin

... snip ...
[mysql]
default-character-set = utf8mb4

[client]
default-character-set = utf8mb4
  • dockerfile
FROM mysql:8.0
RUN chmod 644 /etc/mysql/my.cnf
RUN mkdir -p /var/lib/mysql-files