Docker Basic CheatSheet
Basic Commands:
Container Lifecycle:
docker run: Create and start a container.
1 | docker run -d -name my_container nginx |
docker start/stop/restart: Start, stop, or restart a container.
1 | docker stop my_container |
docker ps: List running containers.
1 | docker ps |
docker ps -a: List all containers (including stopped ones).
1 | docker ps -a |
Image Management:
docker pull: Fetch an image from a registry.
1 | docker pull ubuntu |
docker build: Build an image from a Dockerfile.
1 | docker build -t my_image . |
docker images: List all local images.
1 | docker images |
docker rmi: Remove an image.
1 | docker rmi my_image |
Container Operations:
Interacting with Containers:
docker exec: Execute a command in a running container.
1 | docker exec -it my_container bash |
docker attach: Attach to a running container.
1 | docker attach my_container |
docker logs: View container logs.
1 | docker logs my_container |
Managing Container Resources:
docker cp: Copy files between container and host.
1 | docker cp file.txt my_container:/path/to/destination |
docker pause/unpause: Pause or unpause a running container.
1 | docker pause my_container |
docker inspect: Display detailed container information.
1 | docker inspect my_container |
Networking:
Networking:
docker network ls: List available networks.
1 | docker network ls |
docker network create: Create a new network.
1 | docker network create my_network |
docker network connect/disconnect: Connect or disconnect a container to/from a network.
1 | docker network connect my_network my_container |
Volume Management:
Volumes:
docker volume ls: List volumes.
1 | docker volume ls |
docker volume create: Create a volume.
1 | docker volume create my_volume |
docker volume rm: Remove a volume.
1 | docker volume rm my_volume |
docker volume inspect: Display detailed volume information.
1 | docker volume inspect my_volume |