Docker compose up build fails to update container

The Problem

Solution

docker compose -f docker-compose.prod.yml up --build --no-deps --renew-anon-volumes --detach your_service

What’s behind anonymous volumes

Check for existing anon volumes

docker inspect --type container -f '{{range $i, $v := .Mounts }}{{printf "%v\n" $v}}{{end}}' <your container id>
{volume 277654df19e38eeb10f92be90c8df76558033bcd3c7b871e75abdc14174a46d8 /var/lib/docker/volumes/277654df19e38eeb10f92be90c8df76558033bcd3c7b871e75abdc14174a46d8/_data /opt/app/etc local  true }

How do I create such a volume?

services:
your_service:
build: .
volumes:
- /my_data # anonymous volume
VOLUME  "/var/logs" "/data"
src
config
name.txt
hello-world.sh
Dockerfile
docker-compose.yml
#!/bin/sh
NAME=$(cat /app/config/name.txt)
while sleep 5; do echo "Hello World! Hello $NAME"; done
Max
FROM  alpine
COPY hello-world.sh /app/hello-world.sh
COPY config/name.txt /app/config/name.txt
CMD \["sh","/app/hello-world.sh"\]
services:
hello:
build: ./src
Creating network "docker-anon-volumes_default" with the default driver
Building hello
[+] Building 2.0s (8/8) FINISHED
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
WARNING: Image for service hello was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating docker-anon-volumes_hello_1 ... done
Attaching to docker-anon-volumes_hello_1
hello_1 | Hello World! Hello Max
hello_1 | Hello World! Hello Max
$ docker compose logs -f
hello_1 | Hello World! Hello Max
hello_1 | Hello World! Hello Max
hello_1 | Hello World! Hello Max
$ docker compose logs -f
hello_1 | Hello World! Hello Rudi
hello_1 | Hello World! Hello Rudi
...
$ docker ps        
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1df0f6ee87d4 1c356deb72b1 "sh /app/hello-world…" 40 seconds ago Up 37 seconds docker-anon-volumes_hello_1
$ docker inspect --type container -f '{{range $i, $v := .Mounts }}{{printf "%v\n" $v}}{{end}}' 1df0f6ee87d4
FROM  alpine
COPY hello-world.sh /app/hello-world.sh
COPY config/name.txt /app/config/name.txt
VOLUME /app/config
CMD \["sh","/app/hello-world.sh"\
$ docker compose logs -f
hello_1 | Hello World! Hello Rudi
hello_1 | Hello World! Hello Rudi
...
$ docker compose logs -f
hello_1 | Hello World! Hello Rudi
hello_1 | Hello World! Hello Rudi
...
$ docker ps        
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2419dd47277a 696b927fee44 "sh /app/hello-world…" About a minute ago Up About a minute docker-anon-volumes_hello_1
$ docker inspect --type container -f '{{range $i, $v := .Mounts }}{{printf "%v\n" $v}}{{end}}' 2419dd47277a
{volume c62baf7300ddc9dc66a7e871d6511e5e3a6274072cc20c3f14bb59bca5319935 /var/lib/docker/volumes/c62baf7300ddc9dc66a7e871d6511e5e3a6274072cc20c3f14bb59bca5319935/_data /app/config local rw true }

Fixing Options

docker compose up --build --no-deps --detach --renew-anon-volumes
$ docker compose logs -f
hello_1 | Hello World! Hello Hans
hello_1 | Hello World! Hello Hans
...

Fast-track professional successful in the design, development and deployment of technology strategies and policy. Experienced leading Internet and IS operations

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store