Update So I now realize this is working as intended, but it’s horribly inconvenient. Does anyone know a way for me to persist files that are part of an image when containers are recreated? e.g., my drupal_web Dockerfile downloads the Drupal application to /var/www/html, and if drupal_web gets recreated (e.g., docker-compose up --force-recreate), I want any changes to /var/www/html/sites/default/settings.php to be preserved.
According to https://docs.docker.com/engine/userguide/dockervolumes/#mount-a-host-directory-as-a-data-volume:
“If the path /opt/webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content.”
I seem to have a situation that disproves this:
docker run --rm drupal_web ls /var/www html
So, using the drupal_web image, I clearly see there’s an html directory in
/var/www. If I ls’ed html, I’d see a full Drupal install. In my docker-compose.yml file, I have:
web: ... volumes: - drupal_web_var-www:/var/www
So then I run
docker-compose up -d, and then
docker exec -it drupal_web ls /var/www, and I get nothing.
This seems to contradict the documentation. Making /var/www a volume appears to be wiping out its contents.