Difficulty: beginner
Estimated Time: 10-15 minutes

Digital Academy Logo

Welcome to the Digital Academy "Container Basics" series. This is Module 2 - Creating your own container.

In this lab, we will learn to create our own containers with Docker.

For more information, see the Docker documentation.

Developer(s): William Hearn and Zachary Seguin

Module 2 - Creating Images

Step 1 of 3

Your first Dockerfile

To create your own Docker image you will need to create a Dockerfile.

A Dockerfile defines the layers that will be assembled to create the final image.

Let's take a look at a simple Dockerfile.

cat resources/simple/Dockerfile

Our Dockerfile consists of two instructions:

  1. FROM nginx:1.15

    This instructions tells Docker that we want to extend the official Nginx image.

  2. COPY index.html /usr/share/nginx/html/index.html

    This instructions tells Docker to copy a file into the image.

Now let's build the image and call it simple:

docker build -t simple resources/simple

And let's now run a container based on our image:

docker run --name simple -d -p 80:80 simple

Visit https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/ to see the website. You should see "Hello, World!".

You can now cleanup with docker stop simple && docker rm simple.

Want to try something? Change the contents of resources/simple/index.html and rebuild the image. Run a container based on the new image and see that the contents have now changed.