Docker 部署 - 一台机器 - 无停机时间
Docker deployment - one machine - no downtime
我只有一个小型 Web 项目要 运行 通过 Docker,只有一台机器我不能使用虚拟化,我也不需要它。我想知道如何在不停机的情况下将我的应用程序部署到 VPS 和 Docker。
目前,我只是使用存储库并使用 docker-compose 创建 docker 容器(包括通过特定 .yaml 文件进行生产的一些配置)。
我想最好是使用Swarm,但我认为这是不可能的,因为我只能使用一台机器。
单机部署是 Swarm 的一个很好的用例。如果您的服务可以实现零停机服务更新(假设您的服务有 运行 2 个容器),您可以 "rolling updates"。
显然,您不会有硬件或 OS 级容错,但 Swarm 是比 docker-compose cli 更好的生产解决方案。
在我关于该主题的 GitHub AMA 中查看我在这种情况下使用 Swarm 的所有原因:Only one host for production environment. What to use: docker-compose or single node swarm?
在 example of rolling updates 上观看我的 YouTube 视频。
这是我们在生产中仅使用 nginx
和 docker-compose
的简单方法:https://engineering.tines.com/blog/simple-zero-downtime-deploys
基本上就是这个bash脚本:
reload_nginx() {
docker exec nginx /usr/sbin/nginx -s reload
}
zero_downtime_deploy() {
service_name=tines-app
old_container_id=$(docker ps -f name=$service_name -q | tail -n1)
# bring a new container online, running new code
# (nginx continues routing to the old container only)
docker-compose up -d --no-deps --scale $service_name=2 --no-recreate $service_name
# wait for new container to be available
new_container_id=$(docker ps -f name=$service_name -q | head -n1)
new_container_ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $new_container_id)
curl --silent --include --retry-connrefused --retry 30 --retry-delay 1 --fail http://$new_container_ip:3000/ || exit 1
# start routing requests to the new container (as well as the old)
reload_nginx
# take the old container offline
docker stop $old_container_id
docker rm $old_container_id
docker-compose up -d --no-deps --scale $service_name=1 --no-recreate $service_name
# stop routing requests to the old container
reload_nginx
}
我只有一个小型 Web 项目要 运行 通过 Docker,只有一台机器我不能使用虚拟化,我也不需要它。我想知道如何在不停机的情况下将我的应用程序部署到 VPS 和 Docker。
目前,我只是使用存储库并使用 docker-compose 创建 docker 容器(包括通过特定 .yaml 文件进行生产的一些配置)。
我想最好是使用Swarm,但我认为这是不可能的,因为我只能使用一台机器。
单机部署是 Swarm 的一个很好的用例。如果您的服务可以实现零停机服务更新(假设您的服务有 运行 2 个容器),您可以 "rolling updates"。
显然,您不会有硬件或 OS 级容错,但 Swarm 是比 docker-compose cli 更好的生产解决方案。
在我关于该主题的 GitHub AMA 中查看我在这种情况下使用 Swarm 的所有原因:Only one host for production environment. What to use: docker-compose or single node swarm?
在 example of rolling updates 上观看我的 YouTube 视频。
这是我们在生产中仅使用 nginx
和 docker-compose
的简单方法:https://engineering.tines.com/blog/simple-zero-downtime-deploys
基本上就是这个bash脚本:
reload_nginx() {
docker exec nginx /usr/sbin/nginx -s reload
}
zero_downtime_deploy() {
service_name=tines-app
old_container_id=$(docker ps -f name=$service_name -q | tail -n1)
# bring a new container online, running new code
# (nginx continues routing to the old container only)
docker-compose up -d --no-deps --scale $service_name=2 --no-recreate $service_name
# wait for new container to be available
new_container_id=$(docker ps -f name=$service_name -q | head -n1)
new_container_ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $new_container_id)
curl --silent --include --retry-connrefused --retry 30 --retry-delay 1 --fail http://$new_container_ip:3000/ || exit 1
# start routing requests to the new container (as well as the old)
reload_nginx
# take the old container offline
docker stop $old_container_id
docker rm $old_container_id
docker-compose up -d --no-deps --scale $service_name=1 --no-recreate $service_name
# stop routing requests to the old container
reload_nginx
}