Get Docker running on your machine and deploy your first container in under 12 minutes. This guide covers installation, verification, and running your first containerized application.
Prerequisites
-
Operating System macOS 12+, Ubuntu 20.04+, or Windows 10/11 with WSL2
-
Disk Space At least 4GB free
-
Admin Access sudo/administrator privileges required
Install Docker
Install Docker
~5 minDownload and install Docker Desktop for your platform:
macOS (using Homebrew):
brew install --cask docker
After installation, open Docker Desktop from Applications to complete setup.
Linux (Ubuntu/Debian):
# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Set up the repository
echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Windows:
winget install Docker.DockerDesktop
WSL2 must be installed. Run wsl --install first if needed.
Verify Installation
Verify Installation
~1 minCheck that Docker is installed correctly:
docker --version
Docker version 24.0.7, build afdd53b
Run Hello World
Run Hello World
~1 minTest Docker by running the official hello-world image:
docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
You've successfully pulled and run your first container.
Run an Interactive Container
Run an Interactive Container
~2 minStart an Ubuntu container and get a shell inside it:
docker run -it ubuntu bash
You’re now inside the container. Try running some commands:
# Inside the container
cat /etc/os-release
exit
The -it flags give you an interactive terminal. Type exit to leave.
Run a Web Server
Run a Web Server
~2 minStart an Nginx web server that you can access from your browser:
docker run -d -p 8080:80 --name my-nginx nginx
Open your browser and visit:
http://localhost:8080 →
-d runs in background, -p 8080:80 maps port 8080 on your machine to port 80 in the container.
Manage Containers
Manage Containers
~1 minView running containers:
docker ps
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
a1b2c3d4e5f6 nginx "/docker-entrypoint.…" Up 2 minutes 0.0.0.0:8080->80/tcp my-nginx
Stop and remove the container:
docker stop my-nginx
docker rm my-nginx
Create Your Own Image
Create Your Own Image
~2 minCreate a simple Dockerfile:
# Save this as Dockerfile
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/
EXPOSE 80
Create a simple HTML file:
<!DOCTYPE html>
<html>
<head><title>My Docker App</title></head>
<body><h1>Hello from Docker! 🐳</h1></body>
</html>
Build and run your image:
docker build -t my-app .
docker run -d -p 8080:80 my-app
Visit localhost:8080 to see your custom app running.