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.


    Build, Release and Run Containers with Docker Compose


    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.



    Become a Member to view code

    You must be a Pro 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
    orLog In




    Instructor: 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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.