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.
Interesting course, this one will need to be watched and referenced over and over to absorb all of the good stuff.
Thank you, I agree some of these concepts need repetition in order for them to sick.
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.
Thanks! FYI I have more Docker lessons at:
I actually have a lesson directly pertaining to setting up an nginx proxy:
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.
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
yarn.lock have to be applied to my codebase on my local machine.
@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
this course is a little scattered. seems more like a collection of loosely related lessons than a cohesive course :/
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.
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.