Docker

Modified

October 13, 2024

Docker is a containerization platform. I use it run a host of applications.

Installation

Development

Curtesy of Novaspirit’s Pi-Hosted Series.

Setting up docker in a development environment:

Warning

I only do this on a raspberry pi 4b that I use for testing.

Always read the script first. Using curl to pipe a shell script is always looked down upon. Especially when using sudo.

$ sudo curl -sSL https://get.docker.com | sh || error "Failed to install Docker."
$ sudo usermod -aG docker $USER || error "Failed to add user to the Docker usergroup."

Production

Follow Docker’s official documentation. I use Ubuntu as my production OS.

  1. Set up apt repository:
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
  1. Install docker packages:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Add user to docker group:
$ sudo usermod -aG docker $USER

Config

You can configure the docker daemon by updating the following file: /etc/docker/daemon.json

I recommend updating this config file to store the daemon data to a directory other than the default: /var/lib/docker.

{
  "data-root": "/mnt/docker-data"
}

I run docker as a dedicated LXC in proxmox. Without this modification I found my root partition quickly fill up as I pulled multiple images. This prevented me from updating my system.

Commands

System

Start Daemon

$ systemctl start docker

Prune

Use prune to remove docker objects.

Use system to prune everything. This includes container, network, and image.

To also remove volumes, use the --volumes flag.

$ docker system prune

To remove all images not associated to a container.

$ docker image prune -a

Compose

Start

$ docker compose up

# Detached - Background Process
$ docker compose up -d

Stop

$ docker compose down

Networking

Create

$ docker network create -d bridge NETWORK

Disconnect

$ docker network disconnect {network} {container}
Back to top