Docker named volume is not updated

I am confused about how to use a named data volume (rather than a data container).

I have a named data volume app_src that mounts on /usr/src/app using the app_src file. However, after making changes to the source code (locally), creating the image does not update the volume.

I create an image so

docker-compose -f development.yml build and running it docker-compose -f development.yml up -d .

To confirm that the volume does not change, I am attached to the current container and am quite right, the source code is not updated.

Here is my docker compiling development.yml and Dockerfile for my web service. version: '2'

 services: web: restart: always build: ./web expose: - "8000" volumes: - app_src:/usr/src/app links: - postgres:postgres env_file: development.env command: ./start_web.sh volumes: app_src: {} FROM python:3.4.4 WORKDIR /usr/src/app RUN rm -rf /usr/src/app/* COPY . /usr/src/app/ RUN pip install --no-cache-dir -r requirements.txt 

I could make it work by mounting the host so

 volumes: - ./web/src:/usr/src/app 

I'm running docker 1.11.2 on Ubuntu 16.04. I understand what is wrong? I looked through the documentation, but I could find everything that explained the volume really well.

+8
docker docker-compose docker-volume
source share
2 answers

It looks like you are trying to use docker-compose with named hard mount and Dockerfile to modify the contents of this location. This will not work because the Dockerfile creates the image. The docker-compose command defines a running container that runs on top of this image. You cannot change the volume in creating the image, since this volume is installed only after creating the image that you run in the container.

If you want to update a 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 this container on demand to update your named volume. You can also replace tar with something like git clone to extract from the source repository or even rsync (which you need to install on your image) if you make small changes to the large repository.

You can also work around this by emptying your named volume (either rm -rf / vol / dir, or deleting the volume and creating a new one) and then reloading the container. When the container starts, if an empty named volume is enabled, by default copying the contents of the image at that location in the volume is used.

+7
source share

you mount the volume many times in the same place. The first time container stores data in the host file system, the second time it overrides the data in the INTO container from your host file system. remove the volume assembly from the docker-compose file

volumes: - ./web/src:/usr/src/app #remove this!

you can get more information 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 a container in / opt / webapp. If the path / opt / webapp already exists inside the container image, mount / src / webapp mounts but does not delete the existing content. After removing the mount, the contents are again available. This is consistent with the expected behavior of the mount command.

+1
source share

All Articles