My docker command reference

Created: 2025-04-22

About

I'm not going to go on about the inner workings of docker. There are pleny of posts/tutorials that cover that. Instead this is meant to be a practical guide on how to use docker. However, there is one thing to note, docker has multiple parts, eg. compose, image, context, docker itself. Some parts have overlap with others. The commands below are broken into different sections by those parts. This is a work in progress, so don't be surprised if things are missing. That said, I hope it helps someone other than me.

Starting Docker (Ubuntu/systemd)

Usually docker is enable to start automatically, but if docker ps is not doing anything then you probably need to start it. Docker needs to be started before any of the commands in this file can be used.

systemctl start docker

This will also trigger docker.socket. Alternatively, docker.socket could be started.

Docker relies on a socket. There could be multiples if contexts are being used, (e.g. if you've installed docker desktop. Docker desktop uses a separate context to work)

Stopping Docker (Ubuntu/systemd)

Two commands are needed

Note about networks

Docker compose sets up ap network that can link the containers. The way that the containers can access each other is by their name and the container port, NOT the host port.


docker

ps

Command that returns what containers are up and running

Example: docker ps - The -a option will show all containers not just the running ones.

logs

Fetches the logs for a container. This is helpful when a container crashes

Example: docker logs some-container

rm

Used to delete a container

Example: docker rm some-container


docker image

ls

Used to list images.

Example: docker ls

rm

Used to delete an image. The container should be removed first. force?

Example: docker image rm some-image


docker compose

build

Core command to build the images for an app.

Example: docker compose build

up

Core command to bring up docker containers for an app.

Example: docker compose up -d

The -d option runs it in the background, detached

down

Core command to stop and remove docker containers.

Example: docker compose down

exec

Utility command to run commands in a container

Example: docker compose exec app sh

One usage for this is to connect to the container as shown in the example above. From there the container can be inspected.


docker context

These are interesting. Contexts allow a user to manager multiple docker environments. Most will never use this utility.

ls

Command that lists out the contexts.

Example: docker context ls

use

Command to switch contexts if there are other contexts to switch to. Example: docker context use default

Back