Docker Containers

21 / 30
1 min read
1

Docker Containers

Docker packages an application and its dependencies into a container, a lightweight, isolated environment that runs consistently across machines.

Why Containers?

Consistency - : the same image runs on a developer laptop, CI runner, and production server.
Isolation - : each container has its own filesystem, process space, and network namespace.
Efficiency - : containers share the host kernel, so they are lighter than virtual machines.

Key Concepts

Image - : a read-only blueprint built from a Dockerfile.
Container - : a running instance of an image.
Dockerfile - : instructions to build an image (base image, copy files, install dependencies, expose ports, define the command).
Volume - : persistent storage mounted into a container.

Dockerfile Example

dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Comprehension check

Answer all 3 questions correctly to unlock Submit.

1What is the main advantage of a Docker container over a virtual machine?

2Which file defines how a Docker image is built?

3What instruction in a Dockerfile tells Docker which port the container listens on?