Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker stack deploy rolling updates volume issue

I'm running docker for a production PHP-FPM/Nginx application, I want to use docker-stack.yml and deploy to a swarm cluster. Here's my file:

version: "3"
services:

app:
  image: <MYREGISTRY>/app
volumes:
   - app-data:/var/www/app
deploy:
  mode: global

php:
  image: <MYREGISTRY>/php
volumes:
   - app-data:/var/www/app
deploy:
  replicas: 2

nginx:
  image: <MYREGISTRY>/nginx
    depends_on:
      - php
  volumes:
    - app-data:/var/www/app
  deploy:
    replicas: 2
  ports:
    - "80:80"

volumes:
 app-data:

My code is in app container with image from my registry.

I want to update my code with docker service update --image <MYREGISTRY>/app:latest but it's not working the code is not changed. I guess it uses the local volume app-data instead.

Is it normal that the new container data doesn't override volume data?

like image 409
ninja_dev Avatar asked Mar 15 '17 00:03

ninja_dev


2 Answers

I was having the same issue that I have app and nginx containers sharing the same volume. My current solution having a deploy script which runs

docker service update --mount-add mount service

for app and nginx after docker stack deploy. It will force to update the volume for app and nginx containers.

like image 59
Lecky Lao Avatar answered Sep 22 '22 03:09

Lecky Lao


Yes, this is the expected behavior. Named volumes are only initialized to the image contents when they are empty (the default state when first created). Updating the volume any time after that point would risk data loss from overwriting or deleting volume data that you explicitly asked to be preserved.

If you need the files to be updated with every new image, then perhaps they shouldn't be in a volume? If you do need these inside a volume, then you may need to create a procedure to update the volumes from the image, e.g. if this were a docker run, you could do:

docker run -v app-data:/target --rm <your_registry>/app cp -a /var/www/app/. /target/.

Otherwise, you can delete the volume, or simply remove all files from the volume, and restart your stack to populate it again.

like image 36
BMitch Avatar answered Sep 24 '22 03:09

BMitch