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
- Create a Dockerfile.
- Fork the source code repository on GitHub: https://github.com/linuxacademy/cicd-pipeline-train-schedule-docker
- If you want to clone the repo elsewhere and create the Dockerfile yourself, just be sure to commit and push it to your fork.
- 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" ]
- Here is a sample Dockerfile:
- 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
- Get into your source code directory.
- Build a docker image using your Dockerfile.
- Run the app in a container using the image. Be sure to use port 8080.
- 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