Docker named volume not updating
you mount the volume many times into the same place. First time container stores data into Host file system, second time it override data INTO container FROM your host file system. remove volume mount from you docker-compose file
volumes:
- ./web/src:/usr/src/app #remove this!
you can get additional info here
$ docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
This command mounts the host directory, /src/webapp, into the container at /opt/webapp. 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. Once the mount is removed, the content is accessible again. This is consistent with the expected behavior of the mount command.
A workaround is to recreate the volume, of course, if you can afford longer downtime period:
docker-compose down && docker volume rm <VOLUME_NAME> && docker-compose up -d
It looks like you're trying to use docker-compose with a named volume mount and a Dockerfile to modify the contents of that location. This won't work because the Dockerfile is creating an image. The docker-compose is defining the running container that runs on top of that image. You won't be able to modify the volume within the image creation since that volume is only mounted after the image is created an you run the container.
If you want to update your named volume, consider a side container:
docker run -v app_src:/target -v `pwd`/web/src:/source --rm \
busybox /bin/sh -c "tar -cC /source . | tar -xC /target"
You can run that container on demand to update your named volume. You can also replace the tar with something like a git clone
to pull from a source repository, or even an rsync (which you'd need installed on your image) if you are making small changes to a large repository.
You can also workaround this by emptying your named volume (either rm -rf /vol/dir or removing the volume and creating a new one) and then restarting the container. On the startup of the container, if an empty named volume is included, the default is to copy the image contents at that location into the volume.