

Here’s a ready-to-use Docker Lab in Markdown, including various parameters for each command so students can experiment and understand how each one works. You can copy this directly to your learning portal, documentation, or distribute as a lab handout.
Docker Lab: Essential Container Commands
This hands-on lab introduces you to core Docker container lifecycle commands. Each section explains the command, gives variants with useful parameters, and provides practical exercises to try out.
1. Create a Docker Container
Command:
docker create --name ubuntu-cont ubuntu
Other Options to Try:
# Create with environment variable
docker create --name test-cont -e MYVAR=value ubuntu
# Create and map a port
docker create --name web-cont -p 8080:80 nginx
Code language: PHP (php)
Try:
- Change the container name, image, or add options (ports, volumes, environment variables).
2. Run a Docker Container
Command:
docker run -itd ubuntu
-i
: interactive-t
: terminal-d
: detached (runs in background)
Other Options to Try:
# Run with a name
docker run -itd --name ubuntu-cont ubuntu
# Run and remove container after exit
docker run -it --rm ubuntu
# Run and override entrypoint
docker run -it --entrypoint /bin/bash ubuntu
# Run with port mapping
docker run -d -p 8080:80 nginx
Code language: PHP (php)
Try:
- Change
-itd
to just-it
,-d
, or remove-d
to see the difference. - Add
--rm
to auto-remove the container.
3. Pause a Docker Container
Command:
docker pause <container-id/name>
Code language: HTML, XML (xml)
Try:
- Pause by container name or ID.
- Observe with
docker ps
—container status showsPaused
.
4. Unpause a Docker Container
Command:
docker unpause <container-id/name>
Code language: HTML, XML (xml)
Try:
- Unpause and confirm with
docker ps
.
5. Start a Stopped Docker Container
Command:
docker start <container-id/name>
Code language: HTML, XML (xml)
Other Options:
# Start multiple containers
docker start cont1 cont2 cont3
Code language: PHP (php)
Try:
- Start a single or multiple stopped containers.
6. Stop a Running Docker Container
Command:
docker stop <container-id/name>
Code language: HTML, XML (xml)
Other Options:
# Stop multiple containers
docker stop cont1 cont2 cont3
# Wait 10 seconds before killing the container
docker stop -t 10 <container-id/name>
Code language: PHP (php)
Try:
- Stop with default (10s timeout), or set custom timeout.
7. Restart a Docker Container
Command:
docker restart <container-id/name>
Code language: HTML, XML (xml)
Other Options:
# Restart multiple containers
docker restart cont1 cont2 cont3
# Set restart timeout to 5 seconds
docker restart -t 5 <container-id/name>
Code language: PHP (php)
8. Kill a Docker Container
Command:
docker kill <container-id/name>
Code language: HTML, XML (xml)
Other Options:
# Send a specific signal (e.g., SIGKILL, SIGTERM)
docker kill --signal=SIGKILL <container-id/name>
docker kill --signal=SIGTERM <container-id/name>
Code language: HTML, XML (xml)
9. Remove (Destroy) a Docker Container
Command:
docker rm <container-id/name>
Code language: HTML, XML (xml)
Other Options:
# Remove multiple containers
docker rm cont1 cont2 cont3
# Remove a running container (force)
docker rm -f <container-id/name>
Code language: PHP (php)
Try:
- Remove stopped containers.
- Try to remove a running container without
-f
(should fail).
📝 Lab Exercises
- Create three containers:
- One with a name
- One with a port mapping
- One with a volume mount
- Run and experiment with different flags for
docker run
:
- Try interactive vs detached mode.
- Try
--rm
and observe container removal.
- Pause and unpause a running container. Observe what happens to processes inside.
- Stop and start your containers, then restart one.
- Kill a running container and note the difference vs
stop
. - Destroy (remove) your containers. Try removing running containers with and without
-f
.
🧹 Cleanup
docker ps -a # List all containers
docker stop $(docker ps -q) # Stop all running containers
docker rm $(docker ps -aq) # Remove all containers
Code language: PHP (php)
List of Commands
1 clear
2 ls
3 sudo apt-get update
4 sudo apt-get install ca-certificates curl gnupg lsb-release
5 sudo mkdir -p /etc/apt/keyrings
6 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
7 echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
8 sudo apt-get update
9 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
10 clear
11 dolcker version
12 docker version
13 which docker
14 which dockerd
15 which containerd
16 ps -eaf
17 lear
18 clear
19 docker info
20 clear
21 ls
22 docker ps
23 docker ps -a
24 docker images
25 docker pull httpd
26 docker images
27 clear
28 ls
29 docker create httpd
30 docker ps
31 docker ps -a
32 docker create --name raj1 httpd
33 docker ps -a
34 docker create httpd
35 docker ps -a
36 docker start 9b294ab57cba
37 docker ps -a
38 docker start raj1
39 docker ps -a
40 docker stop 9b294ab57cba
41 docker ps -a
42 docker restart 05f6c329193b
43 docker ps -a
44 clear
45 docker ps -a
46 docker start 9b294ab57cba
47 docker ps -a
48 docker pause 05f6c329193b
49 docker ps -a
50 docker stats
51 docker ps -a
52 docker unpause 05f6c329193b
53 docker ps -a
54 docker kill 9b294ab57cba
55 docker stop 05f6c329193b
56 docker ps -a
57 docker rm 9b294ab57cba
58 docker rm 05f6c329193b
59 docker ps
60 docker ps -a
61 clear
62 docker ps -a
63 docker start 96a5327d4882
64 clear
65 ls
66 docker ps -a
67 ps -eaf | grep container
68 ps -eaf | grep containerd
69 clear
70 docker ps
71 docker exec 96a5327d4882 ps -eaf
72 docker inspect 96a5327d4882
73 docker inspect 96a5327d4882 | grep -i user
74 clear
75 ls
76 docker ps
77 ps -eaf | grep containerd
78 docker ps
79 docker exec -it 96a5327d4882
80 docker exec -it 96a5327d4882 /bin/bash
81 ps -eaf
82 clear
83 docker ps
84 docker inspect 96a5327d4882
85 clear
86 docker exec -it 96a5327d4882 /bin/bash
87 df -kh
88 docker exec -it 96a5327d4882 /bin/bash
89 ls /
90 df -kh
91 cd /var/lib/docker/overlay2/b011c58e3530b49f359d0779fb60153e9622970b601034f035ec881cabbea92f/merged
92 ls
93 clear
94 ls
95 cd
96 ls
97 docker ps
98 history
99 ip a
100 history
Code language: PHP (php)

















I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND