Run One-Off Docker Containers

Mark Shust
InstructorMark Shust

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 3 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.

Stephen James
Stephen James
~ 4 years ago

Interesting course, this one will need to be watched and referenced over and over to absorb all of the good stuff.

Mark Shust
Mark Shustinstructor
~ 4 years ago

Thank you, I agree some of these concepts need repetition in order for them to sick.

Eugene Rwagasore
Eugene Rwagasore
~ 4 years ago

Great course @Mark. I like the load-balancing with nginx part. I was hoping to see how to use nginx as proxy and setup https with letsencrypt. It has proven to be hard to do. Thanks again for this.

Mark Shust
Mark Shustinstructor
~ 4 years ago

Thanks! FYI I have more Docker lessons at:

https://egghead.io/instructors/mark-shust

I actually have a lesson directly pertaining to setting up an nginx proxy:

https://egghead.io/lessons/setup-an-nginx-proxy-for-a-node-js-app

Proxies aren't a part of 12-factor apps (but... maybe they should be!), so I left it out of this course. Thanks for the recommendation, I always used to have a hard time figuring out proxies.

For lets encrypt, at least for non-Docker setups I would highly recommend Certbot. I hope to have a lesson out soon on using certbot/letsencrypt with Docker, as it's been notoriously difficult to set that up.

Michael
Michael
~ 4 years ago

How to run tasks in development that modify the codebase? For example, I'd like to run yarn add <package-name> without installing yarn on my local machine. I'd like to run it in the container (same environment as my app runs). However, the changes to package.json and yarn.lock have to be applied to my codebase on my local machine.

Samuel Okoroafor
Samuel Okoroafor
~ 3 years ago

@Michael, maybe a volume mapping to the codebase directory would help. But you'll need to remove the mapping to your local node_modules directory in docker-compose.yml.

Then execute docker-compose exec <service-name> commands

josh
josh
~ 3 years ago

this course is a little scattered. seems more like a collection of loosely related lessons than a cohesive course :/

Mark Shust
Mark Shustinstructor
~ 3 years ago

I agree -- it's the best I could do with 12-factor, and covering one video per lesson, otherwise this would have been a 30+ lesson course. I'm hoping to cover Docker basics in another course. I'm still hoping this course is very useful though to understand the base concepts of 12-factor apps.

J. Matthew
J. Matthew
~ 2 years ago

I'm hoping to cover Docker basics in another course.

I don't know if you assembled the following playlist of your videos or not, but I found it extremely helpful for answering that exact need: https://egghead.io/playlists/docker-fundamentals-0cb53b55. In my opinion this playlist serves as a de facto "Getting Started with Docker" course.