🐋+🥸

The Opinionated Docker Setup Guide For Develop­ment

Contents

This artcile is written almost entirely because I want to send this to new members of my team(s) and have (hopefully) very similar environments on all our dev machines.

Should You Follow This?

You should only follow this guide if …

  1. You are using Ubuntu (or derivative distros)
  2. You want to reduce pain and maximize joy when working in a team.
  3. (optional) You are an engineer at FringeCore_ (this is an opinion piece)

1. Install Docker

I would highly highly encourage the use of the convenience script to install Docker. I’m actually rather surprised more people aren’t using this method of installation (maybe it’s because it’s not on top of the list).

Terminal window
# we don't want the installer to stick around.
cd /tmp
# ensure you have the right packages
sudo apt install curl
# this one get's the actual installer
curl -fsSL https://get.docker.com -o get-docker.sh
# this one installs it.
sudo sh get-docker.sh

2. Setup Docker Rootless

Using sudo every time you run a docker command is a pain, and often it makes it impossible to automate.

2.1. Setup

Terminal window
# Ensure the dependencies are present.
sudo apt-get install uidmap docker-ce-rootless-extras -y
# Disable the system-wide daemon. (do you really need it on a dev machine?)
sudo systemctl disable --now docker.service docker.socket
# dockerd-rootless-setuptool.sh install
dockerd-rootless-setuptool.sh install

Hopefully the above commands should just run as-is.

2.2. Ask Docker CLI to Use It

Open ~/.bashrc in an editor. (Yes, I use nano. Fight me.)

Terminal window
nano ~/.bashrc

Paste this at the very end.

Terminal window
export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix:///run/user/1000/docker.sock

Save and exit out of the eidtor with Ctrl+O, Enter, Ctrl+X.

2.3. Reload Your Terminal environments

Terminal window
source ~/.bashrc

3. Allow Privileged Ports

Who install nginx on the host machine anymore anyway.

Terminal window
# this one tells your system to allow it.
sudo setcap cap_net_bind_service=ep $(which rootlesskit)
# notice the lack of `sudo`
systemctl --user restart docker

4. Start + Start-up

Terminal window
# start it right now
systemctl --user start docker
# at boot
systemctl --user enable docker

5. Enable Long Running Processes

That don’t exit as soon as you close your terminal.

This section is copied directly from my 🐋 Stop Rootless Docker From Exiting post.

5.1. Enable Linger

Terminal window
sudo loginctl enable-linger $USER

5.2. Edit systemd’s Login Session Config

Open /etc/systemd/logind.conf in a privileged editor.

Terminal window
sudo nano /etc/systemd/logind.conf

Add this to the end.

Terminal window
UserStopDelaySec=infinity
KillUserProcesses=no

Then restart the docker service.

Terminal window
systemctl --user restart docker.service

6. (Optional) Allow Rootless Docker to pass NVIDIA GPU

Open up this file in your text editor. /etc/nvidia-container-runtime/config.toml

Terminal window
sudo nano /etc/nvidia-container-runtime/config.toml

Steps:

  1. Find the line #no-cgroups = false under [nvidia-container-cli]
  2. Uncomment the line.
  3. Change it to true

This will allow rootless docker and docker compose to forward GPU with all its various capabilities to containers.

Done

Enough opinions on how to setup your environment for the day. Welcome to our team.