Intro to Docker Lab

A quick introduction to running Docker containers!

What is Docker?

Docker is a useful tool that allows developers to run software in a standardized environment (similar to the JVM). Unlike virtual machines, it doesn't virtualize computer architecture which makes Docker containers fast and easy to set up. Here's a quick conceptual overview:

Step 1: Install Docker

Here's a link to the main Docker installation page.

Docker Desktop will install Docker Engine (which is what we want!)

Run docker --version in a shell to check if Docker was installed correctly. You may need to modify you computer's PATH variable if it shows up as an invalid command.

Step 2: Running your first container

Download the most recent image of Ubuntu (linux) by running docker pull ubuntu:latest

Create a new Ubuntu container by running docker run -it ubuntu:latest

This should open up an Ubuntu shell. Run some linux commands to verify that the container is running Ubuntu. If you got this working, congrats on running your first Docker container!

Step 3: Run a Full Stack Web Application

Let's do something more interesting. I've created two images for this introductory dummy site and pushed them to Docker Hub, a marketplace for Docker images.

Go to my Docker Hub profile (gabrielsessions) and pull the following images:

gabrielsessions/dfs-jumbocode-intro-frontend

gabrielsessions/dfs-jumbocode-intro-backend

Warning: I created these images on a machine running Linux and an x86 ISA. I have not tested this with an ARM ISA (M1/M2 MacBooks).

Open up the dfs-jumbocode-intro repository on your machine, the most recent version should have a docker-compose.yml file. Please pull from GitHub if you do not have the most recent version of the main branch. Alternatively you can add this file to your current working directory: docker-compose.yml

To run both the backend and frontend servers concurrently, run docker compose up. Both the frontend and backend servers should boot. Verify both servers are working by going to localhost:3000/about and clicking on some of the names.

You can stop the servers with a CTRL-C. If they do not properly shut down after a CTRL-C, you can close the containers manually (run a command like docker compose down).

Step 4: Creating your own Docker Image

Open up the dfs-jumbocode-intro repository in a terminal (on the main branch). You should have a Dockerfile in the root directory.

Open up the Dockerfile and take a look at its structure. You do not need to know what each of the commands do, but try to get a sense of how a Dockerfile sets up a server.

Using this Dockerfile, create a new image for the frontend server. Run docker build . -t my-first-image. This may take a while if the build process is slow.

Now that you have an image set up, you can now build containers with this image. Pushing images to Docker Hub doesn't take too much additional work, but I'll leave the Googling to you.

Step 5: Review Key Concepts

If you read the lab carefully, you should be able to answer these questions:

  1. What is Docker and why is it useful?
    • What is a Dockerfile and what does it do?

      • What is an image? Where can I search up publicly avaliable images?

        • What is a container? How is it different from an image?

          • Outline the process of building and running a container starting from source code.

            • Reflection
              • What are some advantages/disadvantages of using containers over VMs?
              • Besides our DFS web app, can you describe a project (or type of system) where containerization might be useful?
              • What parts of this lab were hard/confusing?