I am trying to inset data files from different images to the named volume so that I can use it in another service for creating database along with seed data. In the below scenario I can see the data-db1 folder created but not data-db2 when I do the compose up. Is this the right way to do or am I missing something here?
The requirement is to have one directory which contains all the different db folders with respective scripts.
Since I can’t mount image as read only volume, I am focusing on this approach.
Appreciate the help if there is a better pattern to this issue.
If you create another container binds to an existing named volume, no files from the new image/container will be copied/overwritten, it will use the existing data inside the named volume.
In case the volume is empty and both containers have data in the target directory the first container to be run will mount its data into the volume and the other container will see that data (and not its own).
Now knowing that only the data from the container that started first is copied, I guess it’s documented, as it won’t be empty for the container that starts second:
Tips for using bind mounts or volumes
If you use either bind mounts or volumes, keep the following in mind:
If you mount an empty volume into a directory in the container in which files or directories exist, these files or directories are propagated (copied) into the volume. Similarly, if you start a container and specify a volume which does not already exist, an empty volume is created for you. This is a good way to pre-populate data that another container needs.
If you mount a bind mount or non-empty volume into a directory in the container in which some files or directories exist, these files or directories are obscured by the mount, just as if you saved files into /mnt on a Linux host and then mounted a USB drive into /mnt . The contents of /mnt would be obscured by the contents of the USB drive until the USB drive were unmounted. The obscured files are not removed or altered, but are not accessible while the bind mount or volume is mounted.