Lab: Build a Containerized Application

In this lab you’ll see how to use a Dockerfile to create a custom container using the docker build command.

This lab expects that you’re using the vagrant box that was built in the Using a Vagrant Configuration Script lab. Or any box with Docker installed. You should have created your application in the Create a Web Application lab.

Step 1: Create a Dockerfile

Like with Vagrantfile a Dockerfile lives in its own directory. You will add the Dockerfile to the ~/MyApp directory alongside the file. Copy and paste the follwing into Dockerfile:

FROM ubuntu:latest
RUN apt-get update && apt-get install -y python3-pip iproute2
RUN pip3 install Flask
ENTRYPOINT ["python3"]
CMD [""]

Step 2: Build Your Container

The docker build command builds a container image from a Dockerfile.

$ docker build -t myapp:latest .

This will pull the base layers and run the commands in the recipe. When it’s done you will be able to deploy your application in a container!

Step 3: Deploy Your Container

With your container layers built you can execute your container with docker run:

$ docker run -p 80:80 myapp 

Step 4: View Your Application

You application is running, you can see it on the same URL as before:

Turn In

Turn in a screenshot of your browser.