Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Docker Lab, Excercise & Assignment – 3

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

CommandWhat it DoesExample
cpCopy files to/from containerdocker cp foo.txt cont:/tmp/
diffShow filesystem changesdocker diff cont
inspectShow low-level object infodocker inspect cont
portShow port mappingsdocker port cont
updateChange container resourcesdocker update --cpu-shares 512
waitWait for container exitdocker wait cont
logsShow container logs (PID 1 output)docker logs cont
psList containersdocker ps -a
statsLive resource statsdocker stats cont
topShow processes in containerdocker top cont
eventsReal-time Docker eventsdocker events

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Here’s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar 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…

Read More

Docker Tutorials: Installation and Configurations

Docker Installation in Centos/RHEL Method -1: How to install Docker Community Edition via YUM? Step 1 – Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data…

Read More

Docker Tutorials: How to Install Docker in Ubuntu?

Install Docker Engine in Ubuntu NOTE – All commands you must run as root user or add a current user into a linux group name called “docker”…

Read More

Docker Lab, Excercise & Assignment – 7 – Docker Volume

Below is a very detailed tutorial and lab manual for learning Docker Volumes, using the Ubuntu image for practical, hands-on labs. This covers all major types of…

Read More

Docker Lab, Excercise & Assignment – 4 – Docker Networking

Here’s an in-depth, step-by-step tutorial and lab manual for Docker Networking—starting from basics, covering all core concepts, and providing a hands-on guide to every feature and command….

Read More