Docker Installation & Config Guide
Docker is an open-source application container engine that allows developers to package their applications and dependencies into a portable container, which can then be published to any popular Linux or Windows machine.
ContainerizationDocker Installation
Linux (Official Install Script)
Suitable for major distributions like Ubuntu, Debian, CentOS. The official script automatically detects the system and installs the latest stable version.
curl -fsSL https://get.docker.com | bashAfter installation, start Docker and enable it to run on boot:
sudo systemctl start docker
sudo systemctl enable dockerWindows
- Ensure your system is Windows 10/11 Pro/Enterprise/Education (supports Hyper-V), or check if WSL 2 is installed.
- Go to Docker Desktop for Windows to download the installer.
- Run the installer and follow the prompts to complete the installation.
- Restart your computer after installation.
macOS
- Go to Docker Desktop for Mac to download the
.dmgfile. - Choose Mac with Intel chip or Mac with Apple chip depending on your chip type.
- Drag the Docker icon to the Applications folder.
Command Cheat Sheet
| Command | Description |
|---|---|
| Image Management | |
docker pull <image> | Pull an image |
docker images | List local images |
docker rmi <id> | Remove an image |
| Container Operations | |
docker run -d -p 80:80 <image> | Run in background and map ports |
docker ps | List running containers |
docker ps -a | List all containers (including stopped ones) |
docker stop <id> | Stop a container |
docker rm <id> | Remove a container |
docker logs -f <id> | View real-time container logs |
docker exec -it <id> sh | Enter container terminal |
Docker Compose (V2)
Newer versions of Docker Desktop and Linux packages include the docker compose command (note the space, no longer docker-compose).
Common Commands:
# Start all services in the background
docker compose up -d
# Stop and remove containers
docker compose down
# View service logs
docker compose logs -f
# Update images and restart
docker compose pull && docker compose up -d⚠️ FAQ
1. Permission Issues (Linux)
Symptom: permission denied when running docker commands. Solution: Add current user to the docker group (run without sudo).
sudo usermod -aG docker $USER
# Log out and log back in, or run this command for immediate effect:
newgrp docker2. Slow / Timeout Image Pulling
Due to network reasons, connecting directly to Docker Hub may fail. It is recommended to configure an image accelerator/mirror.
Edit or create /etc/docker/daemon.json:
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://huecker.io"
]
}Note: Mirrors may become invalid over time, please search for available mirror sources.
Reload configuration and restart service:
sudo systemctl daemon-reload
sudo systemctl restart docker