Docker is one of the most popular tools for pulling, deploying, and managing containerized applications, and for good reason. Compatible with multiple operating systems, this container platform can work on pretty much every computing device under the sun, including the Raspberry Pi. It’s also fairly lightweight and lets you access a massive number of community-created images from the Docker Hub.

However, Docker’s CLI-heavy approach can seem rather complicated for newcomers to the self-hosting space, especially those who are not familiar with the Linux UI. To help you out, we’ve compiled a list of the most useful Docker commands out there.

👁 The MicroK8s Dashboard running on Ubuntu
I installed Kubernetes on my old PC - here’s how I did it

Kubernetes is an amazing platform for all your containerization needs, and here's a simple way to repurpose your outdated PC into a MicroK8s machine

The most important Docker commands for beginners

It’s worth noting that these commands were tested on Docker Engine. If you’re using Docker with the standalone Compose plugin, some commands may differ slightly; however, we’ve included both sets of commands in the list. Also, depending on the distro you’re using, you’ll need to use the sudo keyword at the start of each command to enable administrator privileges for said commands. Alternatively, you can bypass this requirement by running sudo -s and entering the root password inside the terminal.

1 docker pull

Running the docker pull command will grab an image from the Docker Hub. By default, this command downloads the version of the image with the latest tag, but you can use the colon (:) followed by a different tag in case you want to use another variant of the image.

docker pull image_name

2 docker images

Executing images without additional keywords will let you see the details of all the images in your Docker environment. It’s pretty useful when you need to check the ID and tags of your images.

docker images

3 docker build

Alternatively, you can execute the docker build command to create a Dockerfile from the image. You can think of it as an editable document containing the details of your container.

docker build -t image_name

4 docker run

Once you’ve downloaded an image or created a Dockerfile, you can use it with the run command to deploy a container. The docker run command also has a couple of useful flags that let you modify certain aspects of the container without modifying the config file. For instance, the --name flag lets you add a name to the container, while invoking the -p flag allows you to assign the ports to your container.

docker run image_name

5 docker exec

Upon running the exec keyword, you can enter commands inside the container, just like you would on a typical virtual machine. Using exec with the -it container_name sh keywords lets you access the shell interface of the container.

docker exec container_name

6 docker stop

As you may have guessed from the name, the stop command can halt a container, and you won’t be able to access its web UI until you start it again.

docker stop container_name

7 docker start

When you need to deploy a container after stopping it or rebooting your system, you’ll want to enter the start command. If you’ve created a checkpoint for the container, you can add the --checkpoint flag to restore it to its saved state.

docker start container_name

8 docker compose up

Fans of self-hosted services may have come across docker-compose.yml files inside the GitHub repositories of popular projects. While there are some differences between the two, these yaml files act somewhat similar to Dockerfile documents, and you can use them to run an application as a container with the help of the docker compose up command.

docker compose up

If you’re using the Docker Compose standalone plugin, you’ll have to add a hyphen (-) symbol between docker and compose.

👁 raspberry-pi
How to install Docker on your Raspberry Pi

Through the use of Docker, you can quickly get new software and services up and running on your Raspberry Pi. Here's how to get it installed.

By  Jeff Butts

9 docker inspect

The inspect keyword lets you check the ID, host-path, and other config-esque details of a container in the same format as your typical JSON array.

docker inspect container_name

10 docker logs

Entering the docker logs command displays a logbook with the container operational metrics. You can invoke the --details option to get even more details about the container’s operations.

docker logs container_name