Docker Basics: Containers from scratch
Learn Docker by practicing in a terminal inside your browser: containers, images, Dockerfiles, layer caching, volumes, networks, Docker Compose and how to publish your images to a registry.
Kurs-Badge Docker Basics Schließe alle Lektionen ab, um es zu bekommen.
Kursinhalt
First steps
3 LektionenWhat is a container?
The "works on my machine" problem, what a container is, how it differs from a virtual machine, what images are and what Docker is used for.
Installing Docker
How to install Docker Desktop on Windows and macOS or Docker Engine on Linux, check the installation with docker version and docker info, and run your first test container.
Your first container
How docker run works: downloading an image, running a command inside a container, getting in with an interactive terminal (-it), naming it and deleting it when it finishes with --rm.
Working with containers
4 LektionenThe container lifecycle
The states of a container (created, running, stopped), how to list them with docker ps, run them in the background with -d, stop them, start them again and remove them.
Servers, ports and logs
Run a web server in a container, publish its ports with -p to reach it from your computer, and read what happens inside with docker logs.
Getting into and inspecting containers
Run commands inside a container that's already running with docker exec, see its configuration with docker inspect, its processes with docker top, its resource usage with docker stats, and copy files with docker cp.
Configuring with environment variables
Pass configuration to a container with -e and --env-file, see the variables from inside, configure a PostgreSQL database and why secrets don't belong in the image.
Images
5 LektionenImages and Docker Hub
How images are named (registry, user, repository and tag), downloading them with docker pull, listing them, choosing variants like alpine or slim, tagging them with docker tag and removing them with docker rmi.
Your first Dockerfile
Create your own images with a Dockerfile: FROM, WORKDIR, COPY, RUN and CMD, the build context, docker build -t, and how to package a website and a Node app.
Layers and the build cache
How an image is built inside: read-only layers, each container's writable layer, docker history, why the cache speeds up builds and how to order the Dockerfile to take advantage of it.
Dockerfile in depth
More Dockerfile instructions: ENV and ARG for variables, EXPOSE to document ports, LABEL for metadata, the difference between ENTRYPOINT and CMD, and .dockerignore to keep out what shouldn't go in.
Small and secure images
Reduce the size of your images by choosing the right base, installing only what's needed and using multi-stage builds, and make them more secure by running the app as an unprivileged user.
Data
2 LektionenVolumes: data that survives
Why a container's data is lost when you remove it, how to create and use volumes with docker volume and -v, share data between containers, anonymous volumes and read-only mounts.
Bind mounts for development
Mount a folder from your computer inside a container to see changes instantly, develop a Node app with automatic reload, the node_modules trick and when to use a bind mount or a volume.
Networks
2 LektionenDocker networks
How containers communicate: the default bridge network, creating your own networks with docker network, the DNS that resolves containers by name, connecting and disconnecting containers, and the host and none networks.
An app with its database
Connect two containers for real: a Node API that stores a counter in Redis, with its network, its volume and configuration through environment variables, and how to diagnose when they can't find each other.
Docker Compose
3 LektionenYour first compose.yaml
Describe a multi-container application in a compose.yaml file and manage it with docker compose up, ps, logs and down: services, images, build, ports, variables and the network Compose creates for you.
Compose in depth
Wait until the database is ready with healthcheck and depends_on, move configuration to a .env file, separate services into networks, restart policies, and the exec, run and config commands.
Compose for development
Use Docker Compose as a development environment: code mounted with bind mounts, automatic reload, overriding the image's command, rebuilding with --build when dependencies change, and an introduction to compose watch and profiles.
Publishing and production
3 LektionenPublishing images to a registry
Share your images: log in with docker login, name them with your user, push them with docker push to Docker Hub or GitHub Container Registry, version them with tags and download them on another computer.
Cleanup and best practices
See how much space Docker uses and free it with prune without deleting what matters, keep containers alive with restart policies and healthchecks, limit their memory and CPU, and a checklist of best practices for production.
Final project: a complete shop
Dockerize a three-piece application from start to finish (nginx frontend, Node API and PostgreSQL): Dockerfiles, multi-stage build, reverse proxy, separate networks, healthchecks, volumes, Compose and publishing to a registry.