You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Now that you understand what containers are, it is time to install Docker and run your first containers. This lesson covers installation on all major platforms, essential commands for pulling images and managing containers, and how to inspect and debug running containers.
# Remove old versions
sudo apt-get remove docker docker-engine docker.io containerd runc
# Install prerequisites
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Add the repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo \$VERSION_CODENAME) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Add your user to the docker group (avoids needing sudo)
sudo usermod -aG docker \$USER
# Log out and back in for group change to take effect
.dmg file and drag Docker to Applicationsdocker --version
# Docker version 27.x.x, build xxxxxxx
docker info
# Shows daemon info, storage driver, runtime, etc.
docker run hello-world
What happens behind the scenes:
hello-world image locallyYou do not need to run a container to download an image. Use docker pull:
# Pull the latest nginx image
docker pull nginx
# Pull a specific version
docker pull nginx:1.25-alpine
# Pull from a different registry
docker pull ghcr.io/owner/image:tag
docker images
# REPOSITORY TAG IMAGE ID CREATED SIZE
# nginx latest a8758716bb6a 2 weeks ago 187MB
# nginx 1.25-alpine 1e6fd4d1c8b7 3 weeks ago 41MB
The docker run command is the most commonly used Docker command. It creates and starts a container in one step.
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
| Flag | Purpose |
|---|---|
-d | Run in detached (background) mode |
-it | Interactive mode with a terminal (TTY) |
--name NAME | Assign a name to the container |
-p HOST:CONTAINER | Map a host port to a container port |
-e KEY=VALUE | Set an environment variable |
--rm | Automatically remove the container when it exits |
-v HOST:CONTAINER | Mount a volume or bind mount |
# Run nginx in the background, mapping port 8080 to 80
docker run -d --name my-nginx -p 8080:80 nginx
# Run an interactive Ubuntu shell
docker run -it --rm ubuntu bash
# Run with an environment variable
docker run -d --name my-db -e POSTGRES_PASSWORD=secret postgres:16
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.