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.
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)
Two commands are needed
systemctl stop docker
systemctl stop docker.socket
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.
Command that returns what containers are up and running
Example: docker ps
- The -a option will show all containers not just the running ones.
Fetches the logs for a container. This is helpful when a container crashes
Example: docker logs some-container
Used to delete a container
Example: docker rm some-container
Used to list images.
Example: docker ls
Used to delete an image. The container should be removed first. force?
Example: docker image rm some-image
Core command to build the images for an app.
Example: docker compose build
Core command to bring up docker containers for an app.
Example: docker compose up -d
The -d option runs it in the background, detached
Core command to stop and remove docker containers.
Example: docker compose down
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.
These are interesting. Contexts allow a user to manager multiple docker environments. Most will never use this utility.
Command that lists out the contexts.
Example: docker context ls
Command to switch contexts if there are other contexts to switch to.
Example: docker context use default