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.

docker-verison

Images

List all local Docker images:

docker images

alt text

Pull an image from Docker Hub:

docker pull ubuntu

alt text

Containers

Run a container interactively:

docker run -it ubuntu /bin/bash
  • -it: Interactive terminal
  • ubuntu: Image name
  • /bin/bash: Start a Bash shell

alt text

List running containers:

docker ps

alt text

List all containers:

docker ps -a

alt text

Stop a running container:

docker stop <container_id>

alt text

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

alt text

Create a volume:

docker volume create myvolume

alt text

Cleanup

Remove all stopped containers:

docker container prune

alt text

Remove all unused images:

docker image prune

alt text