Thuta Learning
ExercisesDevOps & Toolsintermediate

Docker Practice: Image & Container

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Practice Docker: Image & Container hands-on yourself
  • Practice what you've learned so far and make those skills solid
  • Learn to find mistakes, fix them, and check your own work

Take a moment to think about this

There's no new material in this lesson — the goal is to take the docker run, docker ps, docker exec, and Dockerfile build concepts you've already learned and run them yourself on the command line until they stick. You'll practice hands-on, step by step, from pulling an image all the way to running a container, then going inside the container to run commands. Actually doing this will give you a much better feel for how images and containers differ. Writing and building your own Dockerfile also gives you another chance to walk through the full docker build workflow yourself.

Exercises

Task 1 - Pull the nginx image with docker pull nginx, then run it in the background with docker run -d -p 8080:80 --name my-nginx nginx. Task 2 - Run docker ps and note the NAME and PORTS columns for the running container; use docker ps -a to also see stopped containers. Task 3 - Go inside the container with docker exec -it my-nginx bash, create a file with echo hello > test.txt, then exit. Task 4 - Write your own Dockerfile for a simple Python script and build the image with docker build -t my-app .

Code Example

bash
# Task 1: pull + run
docker pull nginx
docker run -d -p 8080:80 --name my-nginx nginx

# Task 2: list containers
docker ps
docker ps -a

# Task 3: exec into container
docker exec -it my-nginx bash
# container ထဲမှာ:
#   echo hello > test.txt
#   cat test.txt
#   exit

# Task 4: own Dockerfile
# Dockerfile
# FROM python:3.11-slim
# WORKDIR /app
# COPY app.py .
# CMD ["python", "app.py"]

docker build -t my-app .
docker run my-app
You should see
After running all four commands without errors, the container should be in a running state, you should be able to read the file from exec with cat, and your own image should build successfully and run.

5-Minute Try

Within 5 minutes, run an nginx container and check localhost:8080 in your browser. If the default nginx welcome page shows up, you've succeeded.

A Quick Warning

After each practice session, clean up your containers with docker stop and docker rm. Otherwise you'll end up with a pile of leftover containers and run into name conflict errors.

Easy traps

  • Running docker run without the -d flag, which leaves the container's logs blocking your terminal
  • Getting a 'port already in use' error when running docker run because another app is already using port 8080

Now Try It Yourself

Within 5 minutes, run an nginx container and check localhost:8080 in your browser. If the default nginx welcome page shows up, you've succeeded.

You'll know it worked when: After running all four commands without errors, the container should be in a running state, you should be able to read the file from exec with cat, and your own image should build successfully and run.

Docker Practice: Image & Container | Thuta Learning