Sub topic 8
Verifying that Docker works
This chapter assumes you have finished an installation: Docker Engine on Ubuntu with the post-install steps, or Docker Desktop. You should be comfortable in a terminal and know what an image and a container are. The goal is to confirm that each part of the installation works, and to read the output well enough to tell which part is failing when it doesn't.
What a good check proves
Docker is a client and a server. The docker CLI is the client. The daemon (dockerd) is the server, and it does the real work. A working install needs three things:
- The CLI is on your
PATH. - The CLI can talk to the daemon, usually through a Unix socket at
/var/run/docker.sock. - The daemon can pull an image from a registry and start a container from it.
The three commands below test these in order.
Step 1: check the client and the daemon
docker versionThe output has a Client section and a Server section. The Client section is printed even when the daemon is down, so read the Server section carefully. A healthy result looks like this, trimmed:
Client: Docker Engine - Community
Version: 27.3.1
API version: 1.47
Server: Docker Engine - Community
Engine:
Version: 27.3.1
API version: 1.47 (minimum version 1.24)The version numbers on your machine will differ. If the Server section is missing and you see an error, the CLI cannot reach the daemon. The two usual causes are a stopped daemon and missing permission on the socket.
Step 2: check the Compose plugin
docker compose versionThis prints the Compose plugin version, for example Docker Compose version v2.29.7. Note the space: current installs use docker compose (a CLI plugin), not the older standalone docker-compose binary. If you get 'compose' is not a docker command, the plugin package is missing. The next chapter covers Compose and Buildx in more detail.
Step 3: run a test container
docker run hello-worldThis one command exercises the whole chain. The CLI asks the daemon to run hello-world. The daemon doesn't find the image locally, so it pulls it from Docker Hub. It then creates a container, runs it, and streams the output back to your terminal. A successful run prints, among other lines:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
...
Hello from Docker!
This message shows that your installation appears to be working correctly.The first line appears only on the first run. On later runs the image is cached, and you see just the greeting. After the message, the container exits. It is not an error that no container is running afterward.
Reading the result
The failure message tells you which link in the chain broke.
| Symptom | Likely cause | First thing to try |
|---|---|---|
| `permission denied while trying to connect to the Docker daemon socket` | Your user is not in the `docker` group, or the group is not active in this shell | Run `groups` and look for `docker`. Log out and back in, or run `newgrp docker`. |
| `Cannot connect to the Docker daemon ... Is the docker daemon running?` | The daemon is stopped | On Linux, run `sudo systemctl status docker`. On Desktop, start the app. |
| `Unable to find image` followed by a timeout or TLS error | No network route to the registry, often a proxy or firewall | Check connectivity and any proxy settings. |
| `'compose' is not a docker command` | Compose plugin not installed | Install `docker-compose-plugin`. |
Extra checks
Two more commands give useful detail:
docker info
docker ps -adocker info shows the storage driver, the cgroup version, the root directory (/var/lib/docker on Linux Engine), and warnings about missing kernel features. docker ps -a lists all containers, including stopped ones. After the test you should see one hello-world container with status Exited (0). An exit code of 0 means the program finished normally.
You can remove the test container and image when you are done:
docker rm $(docker ps -aq --filter ancestor=hello-world)
docker rmi hello-worldRemove the container first. Docker refuses to delete an image that a container still references.
Exercise
You run docker version and see a full Client section, but the Server section is replaced by "permission denied while trying to connect to the Docker daemon socket". Does the daemon need to be reinstalled? What should you check?
Show answer
No. The CLI is installed and the daemon is probably running. The error means your user cannot access /var/run/docker.sock. Run groups to see whether docker is listed. If it is not, add yourself with sudo usermod -aG docker $USER, then start a new login session or run newgrp docker, and repeat the check without sudo.
Exercise
Why does docker run hello-world print "Unable to find image" the first time but not the second time?
Show answer
The first run has no local copy of the image, so the daemon pulls it from the registry. The pulled image is stored locally, so later runs start the container immediately without pulling.