There are 3 docker containers that need to be restarted automatically whenever the server reboot.
每当服务器重新启动时,都需要自动重新启动3个docker容器。
We can start the containers using restart policies, such as
我们可以使用重启策略启动容器,例如
sudo docker run --restart=always -d your_image
but because one container is linked to another, they need to be started in sequence.
但由于一个容器与另一个容器相关联,因此需要按顺序启动它们。
Questioin: Is there a way to automatically restart Docker containers in sequence?
Questioin:有没有办法按顺序自动重启Docker容器?
1 个解决方案
#1
0
Docker doesn't have an option for this, and doing so is an anti-pattern for microservices. Instead, each container should gracefully return errors when it's dependencies aren't available, or as a fall back, you can use something like a wait-for-it command in your container's entrypoint to wait for your dependencies to be available. I'd also recommend against using "links" and instead place all your services on their own docker network, letting the built in dns resolution handle service discovery for you.
Docker没有这个选项,这样做是微服务的反模式。相反,每个容器应该在它的依赖项不可用时优雅地返回错误,或者作为回退,您可以在容器的入口点中使用类似wait-for-it命令的东西来等待依赖项可用。我还建议不要使用“链接”,而是将所有服务放在自己的docker网络上,让内置的DNS解析为您处理服务发现。
#1
0
Docker doesn't have an option for this, and doing so is an anti-pattern for microservices. Instead, each container should gracefully return errors when it's dependencies aren't available, or as a fall back, you can use something like a wait-for-it command in your container's entrypoint to wait for your dependencies to be available. I'd also recommend against using "links" and instead place all your services on their own docker network, letting the built in dns resolution handle service discovery for you.
Docker没有这个选项,这样做是微服务的反模式。相反,每个容器应该在它的依赖项不可用时优雅地返回错误,或者作为回退,您可以在容器的入口点中使用类似wait-for-it命令的东西来等待依赖项可用。我还建议不要使用“链接”,而是将所有服务放在自己的docker网络上,让内置的DNS解析为您处理服务发现。