Hello there!
Firstly i would like to apologize if i’m posting on the wrong section.
I supose this is may be a simple quest for most of you, but as a beginner i’m finding some things quite complicated to understand at first.
My question is: When i run a “docker run [Apache, PHP, etc…]” it creates by default it’s files, configuration, etc.
All fine.
But when i point a volume to it (Ex. /mnt/data/apache:/etc/apache2) those files that are generated inside the container with the container configs do not get created on the persistent volume…
So, i supose i need to have those files already, on those persistent volumes… But i do not have them.
How do i get the files created in the container and push it to the persistent volume, so i can configurate from there on forth? Because i do not have any configs for Apache. I want to use the default ones created by Apache app…
Thank you. Also, again, sorry if this question is stupid, i really do not know how to do this.
The documentation is ambigous about volumes. Your example does not use a volume at all. It just uses a bind, which litteraly bind mounts a host folder on top of a container folder. As a result the original content of the container folder become invisble, as it is completly eclipsed by the host folder mounted “on top” of it. You won’t see binds listed in docker volume ls
Named volumes that are empty (e.g after beeing created) on the other hand copy the target locations content into the named volume (once !) before they bind the named volume on top of the container folder. You will see named volumes listed by docker volume ls. Keep in mind that If you update files in this path in a newer image, the files will never be used as the old files already exist in the volume - so no copy-on-first-use is triggered.
Personaly I don’t like if images rely on copy-on-first-use. I prefer to emulate the approach by storing the files in a template folder (use whatever folder you like) inside the image and then add functionality to the entrypoint script that checks if one or more of those files already exist in the volume and if not copy the template files into the volume.
Yeah, but its not creating the files… So theres a problem?
it should create the files to specified volumes?
Didnt know that. Well, its not. I did /mnt/data/apache:/etc/apache2 but the folder is empty.
If i run without the volume and enter bash on the container the files are there…
This does declare a bind: /mnt/data/apache:/etc/apache2
This declares a named volume: apache-data:/etc/apache2
Please note that the named volume is just a “handle” and not a host path. Whenever you use a host path, docker will use a bind and not a volume.
With this information, please re-read my previous post. Please ask if you don’t understand particular parts. It doesn’t help if you completly ignore it…