i am trying to create a volume of a directory in a docker container (confluence). https://hub.docker.com/r/atlassian/confluence-server/
To fix a bug with postgres, i have to add driver files manually in the container. The location inside the container is:
/opt/atlassian/confluence/confluence/WEB-INF/lib
After creating the volume i wanted to add the newer driver into the directory. So, inside my docker-compose.yaml i mapped a volume to the directory.
- ./data/driverfiles:/opt/atlassian/confluence/confluence/WEB-INF/lib
Volume and directory get created after calling docker-compose up
and everything seems fine.
Problem is, that the volume remains empty and when starting an interactive shell into the container, the once filles with thousands of files directory is empty, too. When removing the volume from the docker-compose.yaml, the directory is full of files again.
Objectively, it looks like mapping the volume to this directory somehow prohibits the container of enriching it with files, what is going on here?
If you're mounting a host directory over a container directory, at container startup time, this is always a one-way operation: whatever is in the host directory (if anything) completely replaces whatever might have been in the image. Content from a container will never get copied into a host directory unless the image startup code explicitly does this for you.
If you need to modify a configuration file in the container, you need to first copy it out of the image; for example
# with the volumes: mount deleted
docker-compose run confluence \
sh -c 'cd /opt/atlassian/confluence/confluence/WEB-INF/lib && tar cf - .' \
| tar xf - .
That particular invocation will copy the entire directory out to the host, where you can mount it in again.
Note that if there's an updated image that changes the contents of this lib
directory, the content you have on the host will always take precedence; this hides any changes that might be made in the image.
You might find it more reliable to build a custom image that adds the driver files you need
FROM ...conflunce:...
COPY ... /opt/atlassian/confluence/confluence/WEB-INF/lib
# Use CMD and all other options from the original image
Specify build: .
(and no image:
) in the docker-compose.yml
file to use this Dockerfile.