Mounting a specific directory of containerized application via docker compose without overwriting original contents

Hello,

I very recently started usiing and experimenting with docker for some project. E.g. I was using MQTT brokers to test things.
I also wanted to use docker compose to use the containers, and not have to start the docker command manually with all the options.

Next, for configuration, I wanted to start the MQTT broker with my own configuration. So i tried to mound bind the directories to local folders on the host machine. However, this upsets the default installation, not able to find any configuration.

Is there a way, option, or whatever, to just “bind” to that container directory ? Or to at least “copy” what is default present in the docker container ?

E.g., for hivemq-ce, the configuration sits under /opt/hivemq/conf → but when I mount bind this dir, it will be empty,and the services does not start. So ideally, I would have wanted either to “symbollicly” bind this dir, or to copy the default config files over to the mounted dir…

I do not want to use the default docker run … params way, but via the docker compose.
I also tried it with first creating volumes, but this does not work either (or I cannot find HOW to do this)

An advice and examples would be welcome

Common misconception. You don’t bind to the host, you bind from the host overriding what is inside the container.

You can use a custom source dir for the bind and let Docker automatically copy files from the container to the host

But it doesn’t mean you will be able to edit the files without a root user. It is all about Linux and user privileges.

You could try the watch feature of docker compose during development, but then you would need to copy the files from the container to the host first.