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.
[00:00] We're going to start by creating a script that outputs, "Hello, World!" and then, kills itself after three seconds. We will create a Docker file which simply adds this script to our image, and executes it. Let's build this into an image named, Hello, World!
[00:18] Then, run this with a standard Docker run command with a name of Test One. If we check the status with docker ps and filter to show only our Test One image, we can see that the container is exited and is no longer running. Let's try starting another container, this time with the -- restart flag and pass in the value of always.
[00:46] This will restart the container whenever it exits to ensure it's always running. Let's name this container, Test Two. If we go ahead and inspect it now, we will see that the container is still running. Another way to ensure high availability with your containers is to use docker-compose.
[01:11] Create a docker-compose YAML file, and we will define a simple configuration for our Hello, World! App. Make sure to add a restart flag with the value of Always to your configuration. Next, we can easily scale this app with docker-compose up followed by the scale flag. Let's tell compose to start Hello, World! With three instances.
[01:33] We will see that there are still three containers available and always restarting.