How to rebuild and update a container without downtime with docker-compose?

后端 未结 8 1504
春和景丽
春和景丽 2021-01-29 23:00

I enjoy a lot using docker-compose.

Eg. on my server, when I want to update my app with minor changes, I only need to git pull origin master && docker-comp

相关标签:
8条回答
  • 2021-01-29 23:47

    The problem is that restart will restart your current containers, which is not what you want.

    As an example, I just did this

    • change the docker file for one of the images
    • call docker-compose build to build the images
    • call docker-compose down1 and docker-compose up
      • docker-compose restart will NOT work here
      • using docker-compose start instead also does not work

    To be honest, i'm not completly sure you need to do a down first, but that should be easy to check.1 The bottomline is that you need to call up. You will see the containers of unchanged images restarting, but for the changed image you'll see recreating.

    The advantage of this over just calling up --build is that you can see the building-process first before you restart.

    1: from the comments; down is not needed, you can just call up --build. Down has some "down"-sides, including possible being destructive to your (volume-)data.

    0 讨论(0)
  • 2021-01-29 23:47

    You can use Swarm. Init swarm first by docker swarm init command and use healthcheck in docker-compose.yml.

    Then run below command:

    docker stack deploy -c docker-compose.yml project_name

    instead of

    docker-compose up -d.

    When docker-compose.yml file is updated only run this command again:

    docker stack deploy -c docker-compose.yml project_name

    Docker Swarm will create new version of services and stop old version after that.

    0 讨论(0)
提交回复
热议问题