Run One-Off Docker Containers

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 6 years ago

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.

Instructor: [00:00] 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.

[00:16] 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.

[00:38] 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.