Ensure Containers Run with High-Availability

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

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.

egghead
egghead
~ 11 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today