Introduction
Docker is a powerful containerization platform that has revolutionized the way developers build, deploy, and manage applications. In this tutorial, you will learn how to verify your Docker installation and ensure it's working correctly. You will also discover how to troubleshoot common issues that may arise when working with Docker.
By the end of this lab, you will have a solid understanding of how to check Docker installation details and verify that your Docker environment is functioning properly.
This Lab requires an internet connection for learning, thus only Pro users can start the VM. Upgrade your account to Pro
Checking Docker Version and Status
Before diving into Docker operations, it's essential to verify that Docker is properly installed on your system and running correctly. In this step, we'll check the Docker version and daemon status.
Check Docker Version
First, let's check the version of Docker that's installed on your system. Open a terminal and run the following command:
docker --version

This command displays the installed Docker version. You should see output similar to:
Docker version 20.10.21, build baeda1f
For more detailed version information, including both the client and server components, use:
docker version
This will show comprehensive version information for the Docker client and server (daemon), along with other details like the Go version used to build Docker. The output will look something like:
Client:
Version: 20.10.21
API version: 1.41
Go version: go1.18.1
Git commit: baeda1f
Built: Tue Oct 25 18:02:28 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.21
API version: 1.41 (minimum version 1.12)
Go version: go1.18.1
Git commit: 3056208
Built: Tue Oct 25 18:00:19 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.10
GitCommit: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
If you receive an error saying "docker: command not found," it indicates that Docker is not installed correctly or not in your PATH.
Check Docker Daemon Status
Next, let's verify that the Docker daemon (service) is running. The Docker daemon is the background service responsible for managing Docker containers.
Run the following command:
sudo systemctl status docker
You should see output indicating that the Docker service is active and running:
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-05-10 12:34:56 UTC; 2h 15min ago
Main PID: 1234 (dockerd)
Tasks: 8
Memory: 38.5M
CPU: 25.102s
CGroup: /system.slice/docker.service
└─1234 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
If the Docker service is not running, you can start it with:
sudo systemctl start docker
To ensure Docker starts automatically when your system boots, you can enable it:
sudo systemctl enable docker
Check Docker Info
For a comprehensive overview of your Docker installation, use the docker info command:
docker info
This will display detailed information about your Docker installation, including:
- Container and image counts
- Storage driver
- Docker root directory
- Runtime information
- Network settings
- Registry configuration
The output will be quite extensive but provides valuable information about your Docker setup.
Running a Test Container
Now that we've confirmed Docker is installed and running, let's test it by running a simple container. This step will verify that Docker can download images and run containers correctly.
The Hello World Container
Docker provides a simple "hello-world" image specifically designed for testing Docker installations. This tiny container verifies that:
- Docker client can connect to the Docker daemon
- Docker daemon can pull images from Docker Hub
- Docker can create and run a container
Let's run this test container with the following command:
docker run hello-world
When you run this command for the first time, Docker will:
- Check if the hello-world image exists locally
- If not, download it from Docker Hub
- Create a container from this image
- Start the container, which prints a message and exits
You should see output similar to:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:ffb13da98453e0f04d33a6eee5bb8e46ee50d08ebe17735fc0779d0349e889e9
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
This message confirms that your Docker installation is working correctly.
Listing Containers
After running the hello-world container, let's check the list of containers on your system. The container we just ran has already exited, but we can still see it in the list of all containers.
To see all containers (including stopped ones), run:
docker ps -a
You should see output similar to:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b7c33e8f6cb8 hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago romantic_galileo
The -a flag shows all containers, including those that have stopped. Without this flag, docker ps would only show running containers.
Note the STATUS column shows "Exited (0)", which means the container completed its task and exited with a status code of 0 (indicating success).
Listing Docker Images
The hello-world image was downloaded to your local machine. Let's verify this by listing all Docker images:
docker images
You should see output similar to:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 6 months ago 13.3kB
This confirms that the hello-world image is stored locally on your system.
Exploring Basic Docker Commands
Now that we've verified our Docker installation works correctly, let's explore some basic Docker commands that will help you manage containers and images.
Running an Interactive Container
Unlike the hello-world container that runs and exits immediately, we can run containers interactively. Let's run an Ubuntu container and interact with its shell:
docker run -it ubuntu bash
This command:
-ikeeps STDIN open-tallocates a pseudo-TTY (terminal)ubuntuis the image namebashis the command to run inside the container
Once the container starts, you'll be at a bash prompt inside the container:
root@3f4d92618a09:/#
The prompt shows you're logged in as root in the container. The alphanumeric string is the container ID.
Try running some Linux commands inside the container:
cat /etc/os-release
This will display information about the Ubuntu version running in the container:
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
When you're done exploring, exit the container by typing:
exit
This will return you to your host terminal.
Container Lifecycle Management
Let's explore how to manage the lifecycle of a container. First, we'll start a container in detached mode:
docker run -d --name web nginx
This command:
-druns the container in detached mode (in the background)--name webassigns the name "web" to the containernginxis the image to use
You'll see a long container ID printed on the screen.
Now, let's check that the container is running:
docker ps
You should see the nginx container running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7d3f8c1f8a3d nginx "/docker-entrypoint.…" 10 seconds ago Up 10 seconds 80/tcp web
To stop the container:
docker stop web
Verify it's stopped:
docker ps
The container should no longer appear in the list of running containers. To see all containers including stopped ones:
docker ps -a
You should see both the nginx and hello-world containers in the stopped state.
To start the container again:
docker start web
And to remove a container when you no longer need it:
docker stop web
docker rm web
Managing Docker Images
Let's explore how to manage Docker images. To list all images:
docker images
You should see at least the hello-world and nginx images.
To remove an image when you no longer need it:
docker rmi hello-world
Note that you can't remove images that are being used by containers (even stopped ones). You'll need to remove those containers first.
Docker System Information
To check disk space used by Docker (containers, images, volumes):
docker system df
This will show a summary of disk usage:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 2 1 187.8MB 187.8MB (99%)
Containers 2 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
To get more detailed information:
docker system df -v
This will show a breakdown of each image and container and their sizes.
Troubleshooting Common Docker Issues
Even with a properly installed Docker environment, you may encounter issues during regular usage. Let's explore some common Docker problems and their solutions.
Issue: Docker Daemon Not Running
You can skip this step if you have already started the Docker service in the previous step.
If you try to run a Docker command and get an error like this:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
This means the Docker daemon is not running. To resolve this:
- Check the status of the Docker service:
sudo systemctl status docker
- If it's not running, start it:
sudo systemctl start docker
- If the service fails to start, check the logs for errors:
sudo journalctl -u docker
Let's simulate this issue and its resolution:
## First, stop the Docker service to simulate the issue
sudo systemctl stop docker
## Try to run a Docker command
docker ps
## You'll see the "Cannot connect" error
## Now restart the service to fix it
sudo systemctl start docker
## Verify Docker is working again
docker ps
Issue: Permission Denied
If you see an error like:
Got permission denied while trying to connect to the Docker daemon socket
This usually means your user doesn't have permission to access the Docker socket. The solution is to add your user to the docker group:
sudo usermod -aG docker $USER
After running this command, you would normally need to log out and log back in for the changes to take effect. Since we're in a lab environment with the labex user that already has proper permissions, we don't need to perform this step.
Issue: Disk Space Problems
Docker can consume significant disk space over time with unused images, containers, and volumes. If your system is running low on disk space:
- Check Docker disk usage:
docker system df
- Remove unused resources:
## Remove all stopped containers
docker container prune
## Remove all unused images
docker image prune
## Remove all unused volumes
docker volume prune
## Or remove everything unused in one command
docker system prune
Let's demonstrate the pruning command:
## Create some containers that will exit immediately
docker run hello-world
docker run ubuntu echo "This will exit immediately"
## Now prune stopped containers
docker container prune
You'll be asked to confirm the operation:
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Type y to confirm. You should see output showing the removed containers.
Issue: Container Not Starting
If a container fails to start, you can investigate by checking its logs:
## First, try to start a container that might fail
docker run --name failing-container ubuntu apt-get update
## Check the logs
docker logs failing-container
You might see errors in the logs that indicate why the container failed.
Issue: Network Problems
If containers can't communicate with each other or with the outside world:
- Check Docker's network configuration:
docker network ls
- Inspect a specific network:
docker network inspect bridge
- Test connectivity from within a container:
## Start a container with networking
docker run -it ubuntu bash
## From inside the container, install ping
apt-get update && apt-get install -y iputils-ping
## Try pinging a website
ping google.com
## Exit the container
exit
Docker Logs and Debugging
For general Docker troubleshooting, checking Docker daemon logs can be helpful:
sudo journalctl -u docker
For a specific container's logs:
docker logs <container_id>
You can also get a real-time stream of logs:
docker logs -f <container_id>
These troubleshooting techniques will help you diagnose and resolve most common Docker issues.
Summary
In this lab, you've learned essential skills for verifying and managing your Docker installation:
- Checking Docker version and daemon status to confirm proper installation
- Running test containers to verify Docker functionality
- Using basic Docker commands to manage containers and images
- Exploring container lifecycle management
- Troubleshooting common Docker issues
These skills provide a solid foundation for working with Docker containers. You can now confidently verify that your Docker environment is set up correctly and troubleshoot any issues that may arise.
As you continue your Docker journey, you can build upon these fundamentals to create, deploy, and manage containerized applications efficiently.



