Docker named shared assembly volume not updated

I was asked dev ops at the company I'm working on to do something a little different from Docker, then I use it too. The goal is to have 2 containers with the following responsibilities:

Container A: Node, which will create an application for interacting with the external interface and place it in a directory called app/dist/ . When this is completed, the container will stop working.

Container B: An alpine nginx container that will load static files from /usr/share/nginx/html/app .

Files that were created in container A will be provided to Container B using the volume that will mount from <Container A>/app/dist to <Container B>/usr/share/nginx/html/app .

Note that there is a HAProxy container called the app container between the public accessible port and the nginx container.

The above tasks are organized using the docker build file, which is as follows:

 version: '2' volumes: webapp_build_volume: {} services: webapp_build: build: context: . dockerfile: 'config/nginx/dockerfile-builder' volumes: - webapp_build_volume:/app/dist - webapp_static_volume:/app/src/app/static app: build: context: 'config/haproxy' dockerfile: 'dockerfile-app-haproxy' links: - web volumes: - /var/run/docker.sock:/var/run/docker.sock ports: - '80:80' - '1936:1936' web: build: context: . dockerfile: 'config/nginx/dockerfile-web' environment: - EXCLUDE_PORTS=443 - VIRTUAL_HOST=* depends_on: - webapp_build volumes: - webapp_build_volume:/usr/share/nginx/html/app 

Currently, it only works when creating a docker build file. Files in the volume are no longer updated after the volume is created. I read that named volumes cannot be updated after they are created, but I cannot confirm this. I found a job around that included launching docker-compose rm --force && docker volume webapp_build rm , but I would not want to kill cached containers if possible because the CI service will become too slow.

Please let me know if I can clarify everything (I understand that there are a lot of moving parts). Please note that I am also using docker 2 beta, although I don’t see how this can change everything I did here.

+5
source share
1 answer

It’s a little difficult to follow, but it looks like you are creating an image by outputting the files to what you think is the volume and trying to use it to populate the named volume used by another running container.

Most likely, your confusion is that when you create a container, volumes are not mounted, volumes are mounted only in running containers. A named volume has a function in which it will be filled with the contents of the image, but only when mounting a named volume that is empty. It looks like you use this feature the first time you build build +, but it will not work again in future builds. If you run the assembly container without a volume, you will find that your files are there as expected.

You can easily update a named volume. Two options come to mind. One of them is to use your current process, but change the mount point of the volume to something like "/ target" and as your CMD your build container, copy the contents of your source to "/ target". It will look like this:

Dockerfile

 ... RUN compile-cmd --output-to /local/build/dir 

entrypoint.sh:

 cp -a /local/build/dir/* /target/ 

docker-compose.yml:

 version: '2' services: webapp_build: build: context: . dockerfile: 'config/nginx/dockerfile-builder' volumes: - webapp_build_volume:/target ... 

The second option is to not do this in the container assembly at all, but rather make a container with your application that compiles the prerequisites. Then mount your application code as a volume in this container using CMD or ENTRYPOINT , which takes the contents of the code volume, compiles it, and outputs it to the named volume, which is also mounted. Then, instead of creating an assembly container, you simply start the compilation container with two volumes installed.

entrypoint.sh:

 compile-cmd --input-src=/source --output-to /target 

docker-compose.yml:

 version: '2' services: webapp_build: volumes: - app/source:/source - webapp_build_volume:/target ... 
+4
source

All Articles