✦ For everyone, free.

Practical knowledge for real and everyday life

Home

20.1 Beginner Track

A focused guide to Beginner Track, connecting core concepts with practical Docker and container operations.

The beginner track in Docker covers the essential concepts and commands needed to start using Docker for the first time. It focuses on a narrow but functional subset of Docker's capabilities: installing Docker, running pre-built images, understanding the relationship between images and containers, and performing basic lifecycle operations. Everything in the beginner track can be practiced on a single machine with a default Docker installation.

Prerequisite: What Docker Is

Before touching any command, the foundational concept to understand is the distinction between an image and a container.

An image is a read-only blueprint for a container. It packages an application, its runtime, its libraries, and its configuration into a single layered archive. Images are stored in registries (Docker Hub is the default public one) and are identified by a name and tag (for example, nginx:latest or postgres:15).

A container is a running instance of an image. It adds a thin writable layer on top of the image and runs the application process in an isolated environment. Multiple containers can be created from the same image and run simultaneously without interfering with each other.

Image (nginx:latest) Container A Container B

Verifying the Installation

After installing Docker (via Docker Desktop on macOS/Windows or Docker Engine on Linux), verify it works:

docker version

This shows the client and server (daemon) versions. If both appear without errors, Docker is correctly installed and the daemon is running.

docker run hello-world

This pulls a minimal test image, runs it, and prints a verification message. A successful output confirms the entire Docker stack — CLI, daemon, registry connectivity, and container execution — is working.

Pulling and Running Images

Images are pulled from Docker Hub with docker pull:

docker pull nginx:latest

docker run combines pulling (if the image is not already local) and starting a container:

docker run nginx:latest

This runs nginx in the foreground and attaches the terminal to the container output. Press Ctrl+C to stop it.

To run a container in the background (detached mode):

docker run -d nginx:latest

The -d flag starts the container in detached mode and prints the container ID.

Naming Containers

Without a name, Docker assigns a random name. To specify a name:

docker run -d --name my_web nginx:latest

Named containers are easier to manage in subsequent commands.

Listing Containers

To see running containers:

docker ps

To see all containers including stopped ones:

docker ps -a

The output includes the container ID, image, command, creation time, status, ports, and name.

Listing Images

docker images

This shows all images stored locally with their repository, tag, image ID, creation date, and size.

Stopping and Starting Containers

To stop a running container:

docker stop my_web

Docker sends SIGTERM to the container's main process and waits up to 10 seconds for a graceful shutdown before sending SIGKILL.

To start a stopped container:

docker start my_web

Removing Containers and Images

A container must be stopped before it can be removed:

docker rm my_web

To remove a Docker image:

docker rmi nginx:latest

Images cannot be removed if any container (running or stopped) still references them.

Running an Interactive Container

To open a shell inside a container for exploration:

docker run -it ubuntu bash
  • -i: Keep stdin open.
  • -t: Allocate a pseudo-TTY (terminal).

The shell runs inside an Ubuntu container. Changes made here affect only this container and disappear when the container is removed. Type exit to leave the container and stop it.

Viewing Container Output

To see the logs from a container:

docker logs my_web

To follow the log output live:

docker logs -f my_web

First Exposure to Port Mapping

To access an application running inside a container from the host browser, map a host port to a container port:

docker run -d -p 8080:80 --name my_nginx nginx:latest

This maps port 8080 on the host to port 80 inside the container. Opening http://localhost:8080 in a browser shows the nginx welcome page.

Beginner Track Summary

After completing the beginner track, the following operations should be familiar:

TaskCommand
Verify installationdocker version
Run a test containerdocker run hello-world
Run a container in backgrounddocker run -d nginx
List running containersdocker ps
List all containersdocker ps -a
List imagesdocker images
Stop a containerdocker stop name
Start a containerdocker start name
Remove a containerdocker rm name
Remove an imagedocker rmi image
View logsdocker logs name
Open a shelldocker run -it ubuntu bash
Map a portdocker run -p 8080:80 nginx

The beginner track deliberately excludes building images, volumes, networking, and Docker Compose — these are the next stages that build naturally on these foundations.

Content in this section