Customize this training

Get a certificate — $15$5

Docker and Containers Fundamentals

Docker and Containers Fundamentals

Run, build and connect containers with Docker: images, Dockerfiles, volumes, networks and Compose, plus the security habits you need before moving on to Kubernetes.

What you will learn

  • Explain what a container is, how it differs from a virtual machine, and the roles of images, registries, the Docker daemon and the OCI standards.
  • Run, inspect, troubleshoot, stop and remove containers with the Docker CLI, including ports, environment variables and restart policies.
  • Write a clean Dockerfile, understand layers, tags and digests, and use the build cache and multi-stage builds to keep images small.
  • Keep data safe with volumes and bind mounts, and connect containers with user-defined networks and published ports.
  • Describe and run a multi-container application with Docker Compose and manage its lifecycle.
  • Apply basic container security and good practice, and know where Docker stops and orchestration such as Kubernetes begins.

Modules

  1. What containers are and why they matter
  2. Running and managing containers
  3. Images and Dockerfiles
  4. Storage and networking
  5. Multi-container apps with Docker Compose
  6. Security, good practice and the road to Kubernetes

Course facts

Level
Awareness
Estimated study time
about 45 minutes
Final assessment
24 questions · Pass mark 80%
Available in
English, Français, العربية
Price
Free. Optional verifiable certificate: $5
Last updated
Published by
AMAADOR ACADEMY

Who this course is for

Developers, system administrators, IT support staff, students and technical project members who are new to containers, and anyone preparing for the Kubernetes courses in the catalogue.

Prerequisites

Basic command-line use (changing folders, running commands) and a general idea of what an application and a server are. Access to a computer where you may install Docker is recommended for practice, but not required.

Course content

1. What containers are and why they matter

Every team has heard “it works on my machine”. The code runs on the developer’s laptop, then fails on the test server because a library, a runtime version or a setting is different. A container solves this by packaging the application together with everything it needs to run: its code, runtime, system libraries and default settings. The same package then runs the same way on a laptop, a server or a cloud platform.

A container is an isolated process running on the host’s operating system kernel. It is not a small computer. Linux kernel features do the isolation: namespaces give each container its own view of processes, network, file system and host name, and control groups (cgroups) limit how much CPU, memory and disk input/output it can use.

A virtual machine (VM) works differently. A hypervisor emulates hardware, and each VM boots a complete guest operating system with its own kernel.

PointContainerVirtual machine
KernelShares the host kernelOwn guest kernel
Start timeUsually seconds or lessUsually tens of seconds or more
SizeOften megabytesOften gigabytes
IsolationProcess level: good, but weakerHardware level: stronger
Typical usePackaging and running applicationsRunning whole systems or other OS types

2. Running and managing containers

docker run is the command you will use most. It creates a container from an image and starts it. A typical line looks like this: docker run -d --name web -p 8080:80 nginx:1.27.

OptionMeaning
-dDetached: run in the background and give the prompt back
-itInteractive with a terminal, for a shell such as bash or sh
--name webA readable name instead of a random one
-p 8080:80Publish port: host port 8080 forwards to port 80 in the container
-e KEY=valueSet an environment variable (configuration)
--rmDelete the container automatically when it stops
--restart unless-stoppedRestart policy after a crash or a host reboot

The order matters: options come before the image name; anything after the image name is the command to run inside the container. Remember the port order as host:container.

The lifecycle

  1. Created — docker create or the first half of docker run
  2. Running — the main process (PID 1 in the container) is alive
  3. Stopped (exited) — docker stop sends SIGTERM, then SIGKILL after a grace period (10 seconds by default); the container still exists
  4. Restarted — docker start brings the same container back, with its writable layer intact
  5. Removed — docker rm deletes it and its writable layer

3. Images and Dockerfiles

An image is a stack of read-only layers. FROM brings in the layers of the base image, and each instruction that changes files (RUN, COPY, ADD) adds a new layer on top. Layers are shared: if ten images use the same base image, its layers are stored and downloaded only once. When a container starts, Docker adds one thin writable layer on top; changes made inside the container go there and disappear when the container is removed.

Reading an image name

A full reference looks like registry/namespace/repository:tag, for example docker.io/library/python:3.12-slim. If you leave out the registry, Docker uses Docker Hub. If you leave out the tag, Docker uses latest.

ReferenceWhat it isCan it change?
Tag (python:3.12-slim)A human label that points to an imageYes: the publisher can move it to a new build at any time
latestJust the default tag name, not a promise of the newest versionYes
Digest (python@sha256:…)A content hash of the exact imageNo: same digest, same bytes

4. Storage and networking

Containers are meant to be disposable: you replace them with a new version rather than repair them. Anything written to the container’s writable layer is lost when the container is removed. A database, uploaded files or anything you must keep therefore belongs outside the container, in a mount.

TypeWhere the data livesTypical useExample
VolumeStorage managed by DockerDatabases and any persistent application data-v pgdata:/var/lib/postgresql/data
Bind mountA folder you choose on the hostDevelopment: edit code on the host, see it in the container; reading host config files-v ./src:/app/src
tmpfsHost memory only, never written to diskTemporary or sensitive scratch data--tmpfs /tmp

Docker’s documentation recommends volumes for persistent data: Docker creates and manages them, they work the same on Linux, Windows and macOS hosts, they are easy to back up and they can be shared between containers. docker volume ls, docker volume inspect and docker volume rm manage them. The longer --mount syntax (for example --mount type=volume,source=pgdata,target=/var/lib/postgresql/data) is more explicit and is preferred in scripts.

5. Multi-container apps with Docker Compose

A real application is rarely one container. A web shop may need a web front end, an API, a database and a cache. Typing four long docker run commands, in the right order, with the right network and volumes, is slow and error-prone. Docker Compose lets you describe the whole application in one YAML file, usually named compose.yaml, and start it with one command.

A Compose file has three main top-level sections:

SectionWhat it describesExample keys
servicesEach container of the appimage or build, ports, environment, env_file, volumes, depends_on, restart
volumesNamed volumes the services usepgdata:
networksExtra networks, if the default one is not enoughfrontend:, backend:

A typical small file has a service web with build: . and ports: 8080:8000, and a service db with image: postgres:16, a volume pgdata mounted on its data folder, and its password read from an environment file. Compose automatically creates one network for the project and attaches every service to it, so web reaches the database simply at the host name db: the service name is the DNS name.

6. Security, good practice and the road to Kubernetes

An image is software you will run on your servers. Treat it like any other supply-chain component. NIST SP 800-190, the US Application Container Security Guide, lists image vulnerabilities, embedded secrets, malware and untrusted images among the main risks.

  1. Start from a trusted, minimal base — Docker Official Images or Verified Publisher images, slim or minimal variants. Fewer packages mean fewer vulnerabilities.
  2. Scan images — run an image scanner (for example Docker Scout or an open-source scanner) in your CI pipeline and before deployment, and act on critical findings.
  3. Rebuild and redeploy regularly — a scan only helps if you rebuild with patched base images. Use --pull so the build fetches the latest base.
  4. Pin versions and know what you ship — fixed tags or digests, and a software bill of materials (SBOM) if your organisation asks for one.
  5. Keep secrets out of images — no passwords, API keys or tokens in the Dockerfile, ENV lines or copied files.

Why the last point is strict: every layer stays in the image. If you COPY a key file and delete it in a later RUN, it is still readable in the earlier layer by anyone who can pull the image. Pass secrets at run time (environment from a secure store, Compose or orchestrator secrets) or, during a build, with BuildKit secret mounts (RUN --mount=type=secret), which are not saved in the image.

The full lesson continues in the interactive course on this page.

Sources and references

Introductory course. It is not an official Docker, Inc. training and is not affiliated with or endorsed by Docker, Inc. or the Open Container Initiative. Docker is a trademark of Docker, Inc. Commands and defaults change between versions: check the official documentation and your organisation’s rules before using containers in production, and practise on a test machine first.

All courses · DevOps & Platform Engineering — Free certified training | AMAADOR ACADEMY