In this lesson we will cover proper version tagging when building Docker images, creating a docker-compose.yml file for proper release management, and running the tagged release by using Docker Compose to launch app resources as Docker containers.
Instructor: [00:00] Once you have written the Docker file, you can create an executable bundle of your app with the docker build command. This will pull in your app dependencies, and compile binaries and assets into a process that can later be ran as a tagged release.
[00:14] Type docker build, then a -t. What follows is the repo name for the build, which is typically the vendor name, followed by a slash, then the app name. That said, it can also be an arbitrary value. After the repo name is a colon, followed by the tag reversion number.
[00:31] If you leave this part out, it will default this latest, but this is rarely desired in a production build. You want to tag every release with a specific, unique version number. Here, we will use the tag 1.0Then you want a space, followed by the directory you want to build from. We will use a period to specify the current directory.
[00:51] It may take a few moments to run the build process, depending on the size of your base image, install time of dependencies, and asset size and number files being copied to the bundle. After the bundle has been built, we will use docker compose to run our build.
[01:06] Create a file named docker-compose.yaml. This will contain your release configuration. Here's a simple config for our Node.js app. The most important takeaway here is the image property, which should reference the specific tag of the image we just built.
[01:23] This config file, when combined with our tag build, creates our release. Note that we can also define other aspects relating to this release in our config file, such as setting environment variables. After saving this file, we should use version control to commit this release.
[01:40] Before committing, ensure you have both .dockerignore and .gitignore that are set to ignore the .env file in the Node modules directory. Let's add all the files to Git, then commit the release.
[02:02] After committing, we should tag our release with git tag, and use an incrementing version number, in this case, v1.00To run this release for production, we first check out the tag with git checkout v 1.00We create or modify the .env file to our liking on production.
[02:23] This file should not be committed to version control, as it often contains security credentials to third party services. Let's then kick off the production release by running it with docker-compose -d app. This will pull down any Docker images that don't exist on the machine, apply the compose configuration, and start your containers in daemon mode.
[02:45] We can confirm the containers are running by typing docker ps, and follow the log output by running docker logs -f foo_app_1. Upon opening a web browser to the URL localhost:8080, we can see our cat friend Herman.
[03:05] If you desire, you can further optimize the tag, checkout, and production deploy process by creating custom Bash scripts to further automate the process of releasing your software.
Great course! But is there one lesson missing? Where is the lesson how to write the Dockerfile?
Thank you! The Dockerfile referenced is just any Dockerfile you used to create your image. This course assumes some basic understanding of git, node & docker. I did have a complex time figuring out the best way to organize this course, and decided to create one video per one 12-factor concept (that's why there are 12 videos plus the intro video). So, things may seem a bit out of order, but that is organized chaos.
That said, I have many more Docker lessons available at:
You may be particularly interested in this one on how to build your own custom Docker image:
Hope this helps!
You just skipped a lesson on creating docker file?
See my last comment above.
This Video is breaking at 0:16 sec and unable to continue it. I thought it of some technical issue but still facing the problem for almost 50+ hours. Can we fix it?
I am running into some issues where
docker-compose up -d app is not actually running my Docker container. If I run
docker ps -a it appears, but the list is empty if I run
docker ps. I am not experienced in Docker, so I might need to start with your other courses before this one.
I apologize for the belated reply! If an image is not showing with
docker ps but is showing with
docker ps -a, your container exited for what appears to be an unknown reason. You can diagnose this by running
docker logs CONTAINER_ID, and then inspect the output from the container to try to find out what is going on and why the container has exited.