0

I would like to update a container in my docker-compose file: E.g. from sharelatex 0.2 to v0.3.10. How can I do this without loosing the other containers and their data? Is it also possible to create a backup of the current container and switch back to it if the update fails?

My current docker-compse file:

version: '2'
services:
    sharelatex:
        restart: always
        image: sharelatex/sharelatex:0.20
        container_name: sharelatex
        depends_on:
            - mongo
            - redis
        privileged: true
        ports:
            - 80:80
        links:
            - mongo
            - redis
        volumes:
            - ~/sharelatex_data:/var/lib/sharelatex
        environment:
            SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
            SHARELATEX_REDIS_HOST: redis
            SHARELATEX_APP_NAME: 'Our ShareLaTeX'

    mongo:
        restart: always
        image: mongo
        container_name: mongo
        expose:
            - 27017
        volumes:
            - ~/mongo_data:/data/db

    redis:
        restart: always
        image: redis
        container_name: redis
        expose:
            - 6379
        volumes:
            - ~/redis_data:/data

1 Answer 1

1

You should always store any important state (data) in a volume. A container should always be treated as disposable, so when you upgrade the volumes are re-used and you don't lose any data or state.

By default docker-compose up will attempt to re-use any existing containers, as long as their configuration hasn't change. If you only change one service, the other service containers won't be stopped.

In your case it looks like you're already using volumes, so just changing the version and running docker-compose up should do what you want.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! Meaning, when I change image: sharelatex/sharelatex:0.20 to image: sharelatex/sharelatex:latest in the .yml, then docker-compose up would only create a new sharelatex container with the name sharelatex and replace the old one?
Thanks again! Is there a way to keep the old one as backup? How do I have to change the .yml if I want the old one back?
I don't think there is any way to do that right now. I believe docker 1.13 (not yet released) is introducing an experimental "checkpoints" system that would let you store a snapshot of a container. That would let you do what you want.
You can docker commit the old container. This will create an image based on its current state. All data that is not stored in volumes will be included. To access it, you can create instances with docker run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.