Assignments > Lab 4: Intro to Docker

Due Wed, 09/16 at 11:59pm

1. Background

2. Install Docker

Mac

Recommended: install with Homebrew:

brew install --cask docker
docker --version

Then start Docker Desktop (Spotlight → Docker.app). Wait until Docker says it is running.

Verify with:

docker run hello-world

You should see a line that says Hello from Docker!. That means the install worked.

Windows
  1. Install Docker Desktop from Docker’s official guide: Install Docker Desktop on Windows.
  2. During setup, choose the WSL 2 backend if asked.
  3. Do not install or switch to Windows containers / WSLc. This lab uses Linux containers through Docker Desktop.
  4. Start Docker Desktop and wait until it says it is running.
  5. Open PowerShell or your WSL Ubuntu terminal and verify with:
docker run hello-world

You should see Hello from Docker!.

3. Your Tasks

This lab uses your class-exercises-fall2026 fork (not lab03-exercises).

3.1 Get ready (git)
  1. On GitHub: open your fork of class-exercises-fall2026 and sync it with the class repo (csci338/class-exercises-fall2026) using Sync fork / Update branch.

  2. On your computer, in your local class-exercises-fall2026 folder:

    git checkout main
    git pull
    git checkout -b lab04-b
    git branch
  3. Confirm git branch shows * lab04-b.

Before moving on

I am inside class-exercises-fall2026 on branch lab04-b
Docker Desktop is running
docker run hello-world printed Hello from Docker!

3.2 Complete the Docker tutorial
  1. Keep Docker Desktop running.

  2. In a terminal, run:

    docker run -dp 80:80 docker/getting-started
  3. Open http://localhost in your browser.

  4. Complete these tutorial sections (Sharing Our App and Image Building Best Practices are optional):

    1. Getting Started
    2. Our Application
    3. Updating Our App
    4. Optional Sharing Our App
    5. Persisting our DB
    6. Using Bind Mounts
    7. Multi-Container Apps
    8. Using Docker Compose
    9. Optional Image Building Best Practices
  5. As you work, answer the questions in class-exercises-fall2026/lab04/answers.md.

3.3 Put your app files in the right place

When the tutorial is done, your repo should look like this:

class-exercises-fall2026/
  lab04/
    answers.md          ← your written answers
    app/                ← the app folder from the tutorial
      Dockerfile
      docker-compose.yml
      ...other tutorial files...

If the tutorial created app/ somewhere else, move it into lab04/app/ before you submit.

Before moving on

lab04/answers.md is filled in
lab04/app/ exists and includes Dockerfile and docker-compose.yml

4. What to Turn In

  1. Stage, commit, and push branch lab04-b of class-exercises-fall2026 to GitHub.
  2. Open a Pull Request from lab04-b into your main (do not merge — wait for Sarah to review).
  3. Paste the pull request link into the Lab 04 assignment on Canvas.

5. Reference (optional reading)

Use this section if you need a reminder. You do not need to memorize it before starting the tutorial.

What is a container?

A container is an isolated process that runs on a host machine (for example, your laptop).

  • It can run on any machine (and be moved to the cloud)
  • It is isolated from other containers and processes
  • It is created from an image, and can be stopped, started, or deleted
  • Source: https://docs.docker.com/get-started/
What is an image?

A Docker image is a lightweight, read-only template or “blueprint” that contains everything needed to run an application. Images are used to create containers. Dependencies, configurations, scripts, binaries, and metadata (such as environment variables and a default command) live in the image.

Image : Class :: Container : Object

Docker cheatsheet

Images

docker images Lists available images
docker build . Builds an image from a Dockerfile in the current directory (.)
docker build -t <name-of-image> . Builds an image and tags it with that name
docker rmi <your-image-id> Removes an image
Docker Hub Image registry Browse official images

Containers

docker run <name-of-image> Creates and runs a new container from an image
docker ps Lists containers that are currently running
docker stop <container-id> Stops a running container
docker start <container-id> Starts a stopped container
docker rm <container-id> Removes a container
docker exec -it <container-id> sh Runs a shell inside a running container
docker exec -it <container-id> python Runs python inside a container (if python is installed)
Loading quiz...

UNC Asheville Department of Computer Science