DEV Community

DevOps Job Updates
DevOps Job Updates

Posted on Originally published at devopsjobupdates.com

Docker Tutorial for Beginners: Images, Containers and Your First Dockerfile

Docker is the skill that makes the rest of DevOps make sense. Before Docker, running an application meant installing the right language version, the right libraries and the right configuration on every server — and hoping nothing differed between your laptop and production. Docker packages the application and everything it needs into a single portable unit, an image, and runs it as a container. The same image runs on your laptop, in CI, and on a server, with the same behaviour.

This is a shortened version of the full tutorial on DevOps Job Updates. It covers what Docker is, the core commands, your first Dockerfile, volumes and networks, and Docker Compose.

What Docker Is, in Plain Language

A container is a lightweight, isolated process that runs from an image. An image is a read-only template: a layered snapshot of a filesystem containing the application code, its runtime, libraries and configuration. A container is a running instance of an image.

Two ideas matter most. First, images are immutable: you never change a running container's image; you build a new image version and start a new container from it. Second, containers share the host kernel, which is why they start in under a second and use far less memory than virtual machines.

The Core Commands

docker pull nginx:1.27
docker run -d --name my-web -p 8080:80 nginx:1.27
docker ps
docker logs my-web
docker exec -it my-web sh
docker stop my-web
docker rm my-web

A container's filesystem is ephemeral by design. Delete the container and anything written inside it is gone. That is a feature, not a bug — it forces you to keep data somewhere durable.

Writing Your First Dockerfile

A Dockerfile is a recipe for building an image. This multi-stage example builds a small Node.js application:

FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
FROM node:22-alpine
WORKDIR /app
COPY --from=build /app /app
USER node
EXPOSE 3000
CMD ["node", "server.js"]

Build and run it with: docker build -t hello-docker:1.0 . then docker run -d --name hello -p 3000:3000 hello-docker:1.0 then curl http://localhost:3000

Three practices worth copying into every project: use multi-stage builds so the final image contains no build tools; copy dependencies first and code second, so Docker's layer cache works for you; and do not run as root — the USER node line runs the application as an unprivileged user.

Volumes, Networks and Compose

A named volume survives container deletion — this is how a database keeps its data. Containers on the same user-defined network can reach each other by name, so an API container can reach its database at db:5432. And Docker Compose describes a whole multi-container application in one YAML file, so docker compose up -d starts everything at once.

Common Beginner Mistakes

  • Storing data in a container's filesystem instead of a volume.
  • Using latest tags — pin versions, so a rebuild next month produces the same image.
  • Running everything as root.
  • Committing secrets into an image — a secret baked into a layer stays in the layer history even if you delete it later.
  • One giant image — multi-stage builds and a .dockerignore keep images small and easier to scan.

Version note: the latest Docker Engine is 29.10.1 (released 24 Nov 2026). Version 29 is the only supported major line; Docker Engine 28 lost security support in May 2026.

Closing line: This is a shortened version of the full tutorial. Read the complete guide, with the full Dockerfile walkthrough, volumes and networks, Compose example and FAQ, on DevOps Job Updates: https://devopsjobupdates.com/docker-tutorial-beginners/

Top comments (0)