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
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Run One-Off Docker Containers

    Mark ShustMark Shust

    You’ll often need to execute various administrative or maintenance tasks for your app, such as database migrations or arbitrary console commands.

    In this lesson, we will learn how to run arbitrary one-off commands as disposable Docker containers.



    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




    Instructor: Docker containers are cheap, meaning that they take very little disk space and memory to run, and they can be killed off and started very quickly and easily. This disposable nature makes it very easy to run isolated containers that can execute arbitrary tasks.

    Let's use Docker run with the -it flag and the --rm flag. We will run the Ubuntu instance and drop in a Bash. We are now at the Command prompt within the Ubuntu operating system, and can run any command that is available within Ubuntu. Let's exit the prompt.

    If we check the status of all containers, we can see that we don't have any. The --rm flag killed the container when we exited the process. We can also skip the Bash prompt and execute commands directly. Docker started the Ubuntu container, ran our LS command, displayed the output to standard out, exited Ubuntu, and then, killed off the container, all in less than a second.