[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);

 

上一篇:[SQL Server]内存缓存数据写入磁盘(三)延迟持久性Delayed Durability(和魔鬼交易)


下一篇:oracle对象