0

I have a docker compose as such that starts a MySQL db:

version: '3.9'

services:

  mysql_db:
    container_name: mysql_db
    image: mysql
    volumes:
      - mysql_data:/var/lib/mysql
      - /root/mysql/my.cnf:/etc/my.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=pass

volumes:
  mysql_data:
    name: mysql_data

Note that /root/mysql/my.cnf is an empty file in the host and /etc/my.cnf is a non empty file with default configurations for MYSQL server. I was expecting that files on the host behave the same as empty directories on the host, if they are empty they get populated by the files present in the directory on the container.

The goal is here to add some configuration to allow mysql to receive incoming connections from all addresses.

If my file root/mysql/my.cnf has this line:

[mysqld]
bind-address    = 0.0.0.0

it will basically overwrite all default configuration into etc/my.conf

moth
  • 1,833
  • 12
  • 29
  • can you clarify? on one hand you say you want the file inside the container to appear on host, on the other you say you want to use the host file to change the behaviour in the container. docker volumes do not merge files, if that is what you mean. You should copy /etc/my.cnf outside the container, customize it and then map it as a volume for the container to use – Mihai Sep 16 '22 at 08:44
  • yes, I will try to copy and customise and see if it works then. I was expecting docker would copy the file content from the container into the file – moth Sep 16 '22 at 08:50
  • that still did not work. – moth Sep 16 '22 at 09:34
  • Docker bind mounts work the same way as normal Unix filesystem mounts, and the host content always replaces the image content; nothing is automatically copied anywhere. The linked question describes a workaround which takes advantage of copying very specific to Docker named volumes. – David Maze Sep 16 '22 at 11:23

0 Answers0