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

后端 未结 8 1503
春和景丽
春和景丽 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:20

    from the manual docker-compose restart

    If you make changes to your docker-compose.yml configuration these changes will not be reflected after running this command.

    you should be able to do

    $docker-compose up -d --no-deps --build <service_name>
    

    The --no-deps will not start linked services.

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

    Don't manage your application environment directly. Use deployment tool like Rancher / Kubernetes. Using one you will be able to upgrade your dockerized application without any downtime and even downgrade it should you need to.

    Running Rancher is as easy as running another docker container as this tool is available in the Docker Hub.

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

    Though the accepted answer shall work to rebuild the container before starting the new one as a replacement, it is ok for simple use case, but the container will still be down during new container initialization process. If this is quite long, it can be an issue.

    I managed to achieve rolling updates with docker-compose (along with a nginx reverse proxy), and detailed how I built that in this github issue: https://github.com/docker/compose/issues/1786#issuecomment-579794865

    Hope it can help!

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

    Run the following commands:

    docker-compose pull

    docker-compose up -d --no-deps --build <service_name>

    As the top rated answer mentioned docker-compose up -d --no-deps --build <service_name> will restart a single service without taking down the whole compose. I just wanted to add to the top answer in case anyone is unsure how to update an image without restarting the container.

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

    Another way:

    docker-compose restart in your case could be replaced with docker-compose up -d --force-recreate, see https://docs.docker.com/compose/reference/up/

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

    Use the --build flag to the up command, along with the -d flag to run your containers in the background:

    docker-compose up -d --build
    

    This will rebuild all images defined in your compose file, then restart any containers whose images have changed.

    -d assumes that you don't want to keep everything running in your shell foreground. This makes it act more like restart, but it's not required.

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