Home  >  Q&A  >  body text

打包好的docker镜像如何在启动容器前进行测试

项目在docker容器集群上跑, 每次部署会干掉旧容器, 然后根据打包好的新镜像启动容器.
这里有个严重的问题, 就是如果新的镜像出现问题, 旧容器又被干掉, 会导致业务无法访问.
请问是否有办法将打包的镜像先测试能否正确启动容器?

大家讲道理大家讲道理2704 days ago744

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-27 09:04:21

    The cluster is like docker swarm. When upgrading the container image, start the new container first, and then stop the old container after the new container starts normally.
    When Docker starts a container, if the command in the container can start normally, it will be considered that the container starts normally. docker swarm will then stop the old container.
    But for some businesses, it does not mean that the successful start of the process in the container means that the business is normal. At this time, you can use the healthcheck instruction in the Dockerfile to customize the command to check the business health. Only when the result of this command is 0, the container is considered to be started normally, so Swarm only stops the old container. https://docs.docker.com/engin...

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-04-27 09:04:21

    Since it’s already a cluster, isn’t there a hot standby system? Run at least two instances of the same container, one as a backup. When upgrading, upgrade one of them first, then upgrade the rest. Similar to this

    reply
    0
  • Cancelreply