Home
Omar Hosney
Docker Cheat Sheet
Installation and Setup 🛠️
- Install Docker: Use
apt-get install docker-ce
on Ubuntu.
- Start Docker: Run
sudo systemctl start docker
.
- Enable Docker: Enable at startup with
sudo systemctl enable docker
.
- Check Installation: Verify with
docker --version
.
Images 📦
- Pull Image: Download an image with
docker pull <image_name>
.
- List Images: Show images with
docker images
.
- Remove Image: Delete an image with
docker rmi <image_id>
.
- Build Image: Build from a Dockerfile using
docker build -t <image_name> .
.
Containers 🚢
- Run Container: Start a container with
docker run <image_name>
.
- List Containers: Show running containers with
docker ps
.
- Stop Container: Stop a running container using
docker stop <container_id>
.
- Remove Container: Delete a container with
docker rm <container_id>
.
- Run in Background: Use
docker run -d <image_name>
to run in detached mode.
- Run with Ports: Map ports with
docker run -p <host_port>:<container_port> <image_name>
.
Volumes 📂
- Create Volume: Use
docker volume create <volume_name>
.
- List Volumes: Show volumes with
docker volume ls
.
- Use Volume: Mount a volume with
docker run -v <volume_name>:<container_path> <image_name>
.
- Remove Volume: Delete a volume with
docker volume rm <volume_name>
.
Networking 🌐
- List Networks: Show networks with
docker network ls
.
- Create Network: Use
docker network create <network_name>
.
- Connect to Network: Connect a container with
docker network connect <network_name> <container_id>
.
- Disconnect from Network: Disconnect using
docker network disconnect <network_name> <container_id>
.
- Inspect Network: Get details with
docker network inspect <network_name>
.
Docker Compose 📝
- Install Compose: Use
pip install docker-compose
.
- Start Services: Run
docker-compose up
to start.
- Stop Services: Use
docker-compose down
to stop.
- Build Services: Build images with
docker-compose build
.
- View Logs: See logs with
docker-compose logs
.