Here’s a practical Lab Guide/Tutorial for each Docker command you listed, with clear explanations and step-by-step examples using httpd
(Apache) and ubuntu
images.
This is designed so a student can follow on their laptop and actually practice each command.
Docker Command Lab Guide
1. cp
— Copy files/folders between a container and the local filesystem
What it does:
Copies files/folders from your computer to a container or from the container to your computer.
Example:
a. Copying from local to container:
# Start an ubuntu container in detached mode
docker run -dit --name test-ubuntu ubuntu
# Create a test file on your host
echo "Hello from your host!" > myfile.txt
# Copy file into the container's /tmp directory
docker cp myfile.txt test-ubuntu:/tmp/
Code language: PHP (php)
b. Copying from container to local:
docker cp test-ubuntu:/tmp/myfile.txt ./copied_from_container.txt
Code language: JavaScript (javascript)
2. diff
— Inspect changes to files or directories on a container’s filesystem
What it does:
Shows changes (added/modified/deleted files) made to the container since it started.
Example:
docker run -dit --name diff-ubuntu ubuntu
docker exec diff-ubuntu touch /root/newfile.txt
docker diff diff-ubuntu
# Output will show A /root/newfile.txt (A = Added)
Code language: PHP (php)
3. inspect
— Return low-level information on Docker objects
What it does:
Displays detailed JSON info about containers, images, networks, etc.
Example:
docker run -dit --name inspect-httpd httpd
docker inspect inspect-httpd
# Look for "IPAddress", "Mounts", "Config" in the output
Code language: PHP (php)
4. port
— List port mappings or a specific mapping for the container
What it does:
Shows how the container’s ports are mapped to your host.
Example:
docker run -d -p 8080:80 --name httpd-port httpd
docker port httpd-port
# Output: 80/tcp -> 0.0.0.0:8080
Code language: PHP (php)
5. update
— Update configuration of one or more containers
What it does:
Change resource limits (like CPU, memory) for running containers.
Example:
docker run -dit --name update-ubuntu ubuntu
# Update CPU shares to 512 (default is 1024)
docker update --cpu-shares 512 update-ubuntu
Code language: PHP (php)
6. wait
— Block until one or more containers stop, then print their exit codes
What it does:
Waits for a container to stop and prints its exit code.
Example:
docker run --name wait-ubuntu ubuntu sleep 5
docker wait wait-ubuntu
# Output: 0 (means sleep exited successfully)
Code language: PHP (php)
7. logs
— Fetch the logs of a container
What it does:
Shows the output (stdout/stderr) of the main process (PID 1) in a container.
Example:
docker run -d --name logs-httpd httpd
docker logs logs-httpd
docker run --name logs-ubuntu ubuntu echo "Hello from Ubuntu"
docker logs logs-ubuntu
# Output: Hello from Ubuntu
Code language: PHP (php)
8. ps
— List containers
What it does:
Shows all running containers.
Example:
docker ps # Running containers only
docker ps -a # All containers, including stopped
Code language: PHP (php)
9. stats
— Display a live stream of container(s) resource usage statistics
What it does:
Shows CPU, memory, network, and disk stats live.
Example:
docker run -dit --name stats-httpd httpd
docker stats stats-httpd
# Press Ctrl+C to stop viewing stats
Code language: PHP (php)
10. top
— Display the running processes of a container
What it does:
Lists the active processes inside a container.
Example:
docker run -dit --name top-ubuntu ubuntu bash
docker top top-ubuntu
11. events
— Get real time events from the server
What it does:
Shows real-time Docker events (container start/stop, image pull, etc).
Example:
docker events
# In another terminal, start/stop containers to see events in real time
Code language: PHP (php)
12. Detach from container without stopping it:
When you’re attached to a container (e.g., after docker attach
), use:
CTRL + P + Q
(This detaches your terminal from the container, but leaves the container running!)
Lab Flow Example (httpd & ubuntu)
# 1. Start containers
docker run -dit --name myubuntu ubuntu
docker run -d -p 8080:80 --name myhttpd httpd
# 2. Practice each command:
docker cp myfile.txt myubuntu:/tmp/
docker diff myubuntu
docker inspect myhttpd
docker port myhttpd
docker update --cpu-shares 512 myhttpd
docker wait myubuntu
docker logs myhttpd
docker ps
docker ps -a
docker stats myhttpd
docker top myubuntu
docker events
Code language: PHP (php)
Summary Table
Command | What it Does | Example |
---|---|---|
cp | Copy files to/from container | docker cp foo.txt cont:/tmp/ |
diff | Show filesystem changes | docker diff cont |
inspect | Show low-level object info | docker inspect cont |
port | Show port mappings | docker port cont |
update | Change container resources | docker update --cpu-shares 512 |
wait | Wait for container exit | docker wait cont |
logs | Show container logs (PID 1 output) | docker logs cont |
ps | List containers | docker ps -a |
stats | Live resource stats | docker stats cont |
top | Show processes in container | docker top cont |
events | Real-time Docker events | docker events |

















I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights 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 I reviewed , 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 PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND