bonanza
bonanza

Reputation: 280

Upgrade docker container as part of docker-compose

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

Upvotes: 0

Views: 486

Answers (1)

dnephin
dnephin

Reputation: 28050

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.

Upvotes: 1

Related Questions