H
H
Hikmat Abdunabiev2018-03-23 14:42:48
Docker
Hikmat Abdunabiev, 2018-03-23 14:42:48

How to update contents of mounted volume in docker service?

Good afternoon!
There is a docker-compose.yml file:

version: "3.5"

services:
    nginx:
        image: nginx:latest
        depends_on:
            - my-app
            - my-admin
        ports: 
            - 80:80
        volumes:
            - /home/project/data/nginx/conf.d:/etc/nginx/conf.d
            - /home/project/public:/var/public
            - my-admin-volume:/usr/src/app
        networks:
            - my-network
        deploy:
            placement:
                constraints: [node.role == manager]

    my-admin:
        image: my-admin
        env_file:
            - /home/project/ucell.env
        ports:
            - 9000:9000
        depends_on:
            - mariadb
            - redis
            - mongodb
        working_dir: /usr/src/app
        volumes:
            - /home/project/data/log:/var/log/container
            - /home/project/public:/usr/src/app/storage/app/public
            - my-admin-volume:/usr/src/app
        networks:
            - my-network

volumes:
    my-admin-volume:
                
networks:
    my-network:

I start the docker stack with the command:
docker stack deploy -c docker-compose.yml prod
Everything is created and works well. But when I need to update the my-admin image, I run the command:
docker service update --image my-admin:v2 prod_my-admin --force
(v2 here for example).
That volume called prod_my-admin-volume contains the old files from the old my-admin:v1 image. (When creating a stack, docker itself adds the prod_ prefix to the volume name)
In order to update the contents of volume, I do:
docker service update --mount-add type=volume,source=prod_my-admin-volume,target=/usr/src/app prod_my-admin
docker service update --mount-add type=volume,source=prod_my-admin-volume,target=/usr/src/app prod_nginx

But it still doesn't update.
But if you delete the running stack, volume with the name prod_my-admin-volume
and re-create the stack, then all new files are visible.
Q: How can I update the contents of a mounted volume without recreating the stack? Has anyone encountered such a situation? If possible, indicate in which direction to dig ?!
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-03-24
@sah4ez32

So volume it just about it. Saving data.
The question is what do you have in volumes. You can try running a one-time data migration job. In the form of a container and a list of commands.
But I also advise you to reconsider approaches to using docker.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question