V
V
Vadim_laka2020-03-02 13:31:53
Docker
Vadim_laka, 2020-03-02 13:31:53

How to force volumes Docker compose not to overwrite data from a container?

Forwarding a volume to docker-compose

volumes: 
   - ./www:/var/www/html


I expect that the files from the var/www/html directory will get to the host in ./www
But it’s not that nothing gets there, but it also overwrites everything in the container at this address.
It's already been said that this is normal behaviour. But here is one thing.
If I use the official wordpress image from the dockerhub, then by mounting the verdpress root on the host, the data will be displayed on my host and will not be lost in the container. So how can this be done. I wonder how

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-03-02
@Vadim_laka

I expect that files from the var/www/html directory will get to the host in ./www

No. Vice versa. Mounted something (folder or docker volume) inside the container, replacing the folder that previously existed (if) in the container. Or an individual file.
volumes: 
   - /папка_на_хосте:/папка_в_контейнере_1
   - имя_тома:/папка_в_контейнере_2
After that, if a file is created inside the container in this folder, it ends up in the host_folder or volume. WordPress looks
at startup to see if its files are in the folder. And if the folder is empty, it installs, unpacks all its files into it. In this case, of course, once the host folder is mounted, all files appear in it. Those. there are initially no files in the container in - be it a container folder or a host folder mounted into it or a docker volume. On startup, if it's empty, files are created/written by the container. If you want the same, create a bash script in which you place the application initialization logic, incl. copy-create files. Specify it as ENTRYPOINT
entrypoint.shcontainer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question