Search code examples
dockerdocker-swarmdocker-swarm-modedocker-stack

Docker stack doesn't update container data by tag


I'm trying to setup zero downtime deploy with docker stack. I succeeded running everything on the server, but when i try to update existing stack with a new tag, data in container doesn't changes. No errors occur and docker stack ps outputs information that new images are used. Tryed to remove the stack, container, image and clear cache by docker system prune, but it doesn't works. I can see a new data only when creating a new stack with unique name or deleting /var/lib/docker folder. And also, if i try run an image by docker run , there will be actual data. In general, everything looks as if there is some kind of cache for docker stack, but i don't know where is it...

docker-compose.deploy.yml

version: '3.7'
...
php-fpm:
    image: registry.com/web/idm/php-fpm:${IMAGES_TAG}
    depends_on:
      - database
      - redis
    deploy:
      update_config:
        order: start-first
        failure_action: rollback
        delay: 10s
      rollback_config:
        parallelism: 0
        order: stop-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s
    volumes:
      - php_files:/var/www
    networks:
      - acs_back

Deploy script on runner

env $( cat .env | grep ^[A-Z] | xargs) IMAGES_TAG=${CI_PIPELINE_ID} docker-compose build --pull
IMAGES_TAG=${CI_PIPELINE_ID} docker-compose push

Deploy script on server

docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} && \
env \$(cat $DEPLOY_PATH/env.file | grep ^[A-Z] | xargs) IMAGES_TAG=${CI_PIPELINE_ID} docker-compose -f $ACTUAL_PATH/docker-compose.deploy.yml pull && \ # Without it sometimes throw errors "unable find image..."
env \$(cat $DEPLOY_PATH/env.file | grep ^[A-Z] | xargs) IMAGES_TAG=${CI_PIPELINE_ID} docker stack deploy -c $ACTUAL_PATH/docker-compose.deploy.yml access-control --with-registry-auth

Thanks for your help!


Solution

  • I found out what the problem was. I created a mount volume between php-fpm and nginx - php_files. Apparently, because the services are updated one by one, the mounted directory has never been updated. By removing the shared directory and uploading files to nginx separately, the problem no longer arises.