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