Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Ensure Containers Run with High-Availability

    Mark ShustMark Shust

    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.

    dockerDocker
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss