↓Skip to main content

Installing Docker rootless mode on Ubuntu

·2 mins

I find it very convenient to run docker containers on my Ubuntu Linux Laptop, so that i can quickly crank up docker images with the latest database versions of postgres, and do testing. When you install Docker on ubuntu, by default, the docker deamon dockerd runs as root.

I prefer to run the docker deamon process as a non root ubuntu user, below are the steps that i follow in order to set this up.

Docker Installation Instructions - Ubuntu

First I configure the apt repositories for Ubuntu, running the following commands as root


# Add Docker's official GPG key:
sudo apt update
sudo apt 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:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

Then I install the Docker packages, again as root

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that Docker is running

sudo systemctl status docker

Now we can configure ubuntu to run as a non root user. Docker - Rootless Configuration. First we stop the docker deamon running as root and disable it for good.

sudo systemctl disable --now docker.service docker.socket
sudo rm /var/run/docker.sock

Now switch to the Ubuntu user (Non-root) where you want the Docker engine to be running from.

dockerd-rootless-setuptool.sh install

Run the following command to confirm that the docker client is connecting to the rootless deamon

docker info

Now you have Docker running as a non-root user on Ubuntu