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
# 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-appAfter 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.