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 Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals