03 Basic Commands - Jermmyy/IT-Landscape GitHub Wiki
Basic Commands
Docker provides a powerful command-line interface (CLI) to interact with containers, images, volumes and more. Below is an overview of the most essential commands.
Viewing Installed Docker Version
docker --version
Displays the installed docker version.
Images
List all local Docker images:
docker images
Pull an image from Docker Hub:
docker pull ubuntu
Containers
Run a container interactively:
docker run -it ubuntu /bin/bash
-it
: Interactive terminalubuntu
: Image name/bin/bash
: Start a Bash shell
List running containers:
docker ps
List all containers:
docker ps -a
Stop a running container:
docker stop <container_id>
Start a stopped container:
docker start <container_id>
Remove a container:
docker rm <container_id>
Container Flow Example
docker run --name test-container ubuntu sleep 60
docker ps
docker stop test-container
docker rm test-container
Volumes
List all volumes:
List all volumes:
docker volume ls
Create a volume:
docker volume create myvolume
Cleanup
Remove all stopped containers:
docker container prune
Remove all unused images:
docker image prune