Dockerizing an App

45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Docker is a great tool for running and orchestrating software. However, to effectively use Docker, you will first need to know how to run an app using Docker. In this hands-on lab, you will learn how to dockerize an app by creating a Docker image for an application and running the image as a Docker container. After completing this exercise, you will gain basic knowledge to configure an existing application to use Docker.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Dockerfile for the Application
  1. Create a Dockerfile.
  2. Fork the source code repository on GitHub: https://github.com/linuxacademy/cicd-pipeline-train-schedule-docker
  3. If you want to clone the repo elsewhere and create the Dockerfile yourself, just be sure to commit and push it to your fork.
  4. If you would like to create the file in GitHub itself, then use the Add file then Create new file button when viewing the GitHub repo.
    • Here is a sample Dockerfile:
      FROM node:carbon
      WORKDIR /usr/src/app
      COPY package*.json ./
      RUN npm install
      COPY . .
      EXPOSE 8080
      CMD [ "npm", "start" ]
  5. Once you have a docker file, log in to the learning activity environment and clone your fork inside the cloud_user home directory.
Build a Docker Image Using the Dockerfile and Run It
  1. Get into your source code directory.
  2. Build a docker image using your Dockerfile.
  3. Run the app in a container using the image. Be sure to use port 8080.
  4. Once the container is running, you should be able to access the train schediule app in a browser: http://<your learning activity environment public IP>:8080

Additional Resources

Your team is building the train-schedule app. They want to transition to using containers to run the app in production. The app will need to be built into a docker image. The team has asked you to write a Dockerfile for the train-schedule app. It must also be verified, so it can be used to build an image and run in a container.

Create a Dockerfile for the application:

  • Fork the sample source code on GitHub.
  • Clone the fork to your home directory in the learning activity environment.
  • Create a Dockerfile and commit it.

Build a Docker image using the Dockerfile and run it:

  • Use docker build to build the docker image.
  • Use docker run to run a container using the image.
  • Verify that the app is running by accessing the train schedule app at http://<activity environment public ip>:8080.

Feel free to look at the example-solution branch of the git repo for an example of the source code changes needed for the solution.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?