0
0
Dockerdevops~5 mins

Docker architecture (client, daemon, registry) - Commands & Configuration

Choose your learning style9 modes available
Introduction
Docker helps you run apps inside containers. It uses three main parts: the Client to give commands, the Daemon to do the work, and the Registry to store container images.
When you want to build a container image on your computer and run it locally.
When you need to download a ready-made app image from the internet to run it.
When you want to share your app image with others by uploading it to a central place.
When you want to check which images are stored on your computer.
When you want to stop or remove containers running on your machine.
Commands
This command shows the versions of the Docker Client and Daemon to confirm they are installed and communicating.
Terminal
docker version
Expected OutputExpected
Client: Docker Engine - Community Version: 24.0.2 API version: 1.42 Go version: go1.20.5 Git commit: 123abc4 Built: Thu May 2 15:00:00 2024 OS/Arch: linux/amd64 Server: Docker Engine - Community Engine: Version: 24.0.2 API version: 1.42 (minimum version 1.12) Go version: go1.20.5 Git commit: 123abc4 Built: Thu May 2 15:00:00 2024 OS/Arch: linux/amd64 Experimental: false
This command downloads the nginx image version 1.25.2 from the Docker Registry to your local machine.
Terminal
docker pull nginx:1.25.2
Expected OutputExpected
1.25.2: Pulling from library/nginx Digest: sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890 Status: Downloaded newer image for nginx:1.25.2 docker.io/library/nginx:1.25.2
This command lists all container images stored locally on your machine.
Terminal
docker images
Expected OutputExpected
REPOSITORY TAG IMAGE ID CREATED SIZE nginx 1.25.2 123abc456def 2 days ago 133MB
This command tells the Docker Daemon to start a container named 'my-nginx' in the background, mapping port 8080 on your computer to port 80 inside the container.
Terminal
docker run --name my-nginx -d -p 8080:80 nginx:1.25.2
Expected OutputExpected
a1b2c3d4e5f678901234567890abcdef1234567890abcdef1234567890abcdef
--name - Assigns a name to the container for easier management
-d - Runs the container in detached mode (in the background)
-p - Maps a port on the host to a port in the container
This command shows all running containers managed by the Docker Daemon.
Terminal
docker ps
Expected OutputExpected
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1b2c3d4e5f6 nginx:1.25.2 "/docker-entrypoint.…" 10 seconds ago Up 9 seconds 0.0.0.0:8080->80/tcp my-nginx
Key Concept

Docker Client sends commands to the Daemon, which manages containers and images, while the Registry stores and shares images.

Common Mistakes
Trying to run docker commands without the Docker Daemon running.
The Client cannot communicate with the Daemon, so commands fail.
Make sure the Docker service/daemon is running before using docker commands.
Pulling an image without specifying the correct tag.
Docker pulls the 'latest' tag by default, which may not be what you want.
Always specify the exact image tag like 'nginx:1.25.2' to get the right version.
Not mapping ports when running a container that serves web traffic.
The app inside the container won't be accessible from your computer without port mapping.
Use the -p flag to map container ports to host ports, e.g., -p 8080:80.
Summary
Use 'docker version' to check Client and Daemon communication.
Use 'docker pull' to download images from the Registry.
Use 'docker run' to start containers with port mapping.
Use 'docker ps' to see running containers.