Docker on Ubuntu: My Most Used Commands

When I started using Docker on my Ubuntu machine, I kept googling the same commands again and again.

This post is basically my personal cheat sheet of Docker commands I use all the time on Ubuntu, with short explanations and copy-paste examples.

Target: you already have Docker installed and just want to be productive with containers and images.


1. Basic info & sanity checks

Check Docker version

docker --version

Good for verifying Docker is installed and which version you’re running.

Check if the Docker daemon is running

sudo systemctl status docker

If it’s not running:

sudo systemctl start docker

To make Docker start on boot:

sudo systemctl enable docker

2. Images: what’s on my machine?

List all images

docker images

This shows:

Pull an image

docker pull nginx:latest

If you omit the tag, Docker uses :latest by default:

docker pull ubuntu

Remove an image

docker rmi IMAGE_ID

If the image is still used by containers, you’ll need to remove those containers first.


3. Containers: running stuff

Run a container (simple example)

docker run -it --name my-ubuntu ubuntu bash

What this does:

When you exit bash, the container stops.

Run a container in the background (detached)

docker run -d --name my-nginx -p 8080:80 nginx

Then open:

http://localhost:8080

4. Listing, starting, stopping containers

Show running containers

docker ps

Show all containers (including stopped)

docker ps -a

Stop a running container

docker stop CONTAINER_ID

or:

docker stop my-nginx

if you gave it a name.

Start a stopped container

docker start CONTAINER_ID

or by name:

docker start my-nginx

Remove a container

docker rm CONTAINER_ID

If the container is running, stop it first:

docker stop CONTAINER_ID
docker rm CONTAINER_ID

5. Looking inside containers

See logs

docker logs my-nginx

Follow logs in real time (like tail -f):

docker logs -f my-nginx

Execute a command inside a running container

docker exec -it my-nginx bash

or, if the container doesn’t have bash, try sh:

docker exec -it my-nginx sh

I use this all the time to “inspect” what’s happening inside a container.


6. Volumes & bind mounts (quick basics)

Run a container with a bind mount

Map a folder from your Ubuntu host into the container:

docker run -d --name my-nginx \
  -p 8080:80 \
  -v /home/user/html:/usr/share/nginx/html \
  nginx

Anything you put in /home/user/html will be served by Nginx.

List Docker volumes

docker volume ls

Inspect a volume

docker volume inspect VOLUME_NAME

7. Cleaning up (when your disk is crying)

Docker can fill disk space quickly with old images, stopped containers and unused volumes.

Remove stopped containers

docker container prune

You’ll be prompted to confirm.

Remove unused images

docker image prune

Remove all unused images (not only dangling ones):

docker image prune -a

Remove unused volumes

docker volume prune

Remove almost everything not in use

docker system prune

Or more aggressive:

docker system prune -a

Be careful: this removes all unused images, containers, networks, and caches.


8. Docker Compose (bonus section)

If you use docker-compose.yml files, these are the commands I use the most.

Start all services in the background

From the folder that contains docker-compose.yml:

docker compose up -d

(or docker-compose up -d on older setups).

See logs for all services

docker compose logs

Follow logs (live):

docker compose logs -f

Stop and remove containers (but keep images & volumes)

docker compose down

If you also want to remove named volumes defined in the file:

docker compose down -v

9. My personal mini–cheat sheet

On Ubuntu, these are the ones I type all the time:

# Check containers
docker ps
docker ps -a

# Start / stop
docker start NAME_OR_ID
docker stop NAME_OR_ID

# Logs & shell
docker logs -f NAME
docker exec -it NAME bash

# Images
docker images
docker pull IMAGE
docker rmi IMAGE_ID

# Cleanup
docker container prune
docker image prune -a
docker system prune

# Docker Compose
docker compose up -d
docker compose down
docker compose logs -f

I keep this list in my notes so I don’t Google the same commands every week 😅

In next posts, I’ll probably dive into:

aria

© 2025 Aria

Instagram 𝕏 GitHub