其他分享
首页 > 其他分享> > [Docker] Ensure Containers Run with High-Availability

[Docker] Ensure Containers Run with High-Availability

作者:互联网

A properly scaled Docker architecture should be able to kill off random containers at any time, and continue to run by implementing a crash-only design methodology. We will learn how to setup our architecture to auto-spawn new Docker containers when other containers are deemed unhealthy or in a terminated state. We will also learn how to scale containers easily with Compose in the event we need to quickly scale horizontally.

 

For example we have a nodejs image called helloworld:

Dockerfile:

FROM mhart/alpine-node
COPY index.js .
CMD node index.js

 

To ensure high availablity, we can pass --restart:

docker run --restart always --name test helloworld

 

Another way is using docker-compose.hml:

version: '3'
services:
  helloworld:
    image: helloworld
    restart: always

 Run:

docker-compose up --scale helloworld=3  ## 3 instants

 


 

index.js

console.log('hello world');

setTimeout(() => process.exit(), 3000);

 

标签:index,scale,Run,--,helloworld,High,Ensure,restart,containers
来源: https://www.cnblogs.com/Answer1215/p/14365046.html