Docker Configuration for Non-Privileged Users on Linux#

This document details the procedure for configuring Docker so that containers, including the spkg container, may be built and executed without requiring superuser privileges.

1. Install Docker Engine#

There are two installation approaches. Select Option A for a simpler installation using the docker.io package, or Option B for the most current official release.

Update the package index and install docker.io:

sudo apt update
sudo apt install -y docker.io

2. Verify Docker Operation#

Ensure the Docker daemon is active and verify the installation:

sudo systemctl start docker
sudo systemctl enable docker
docker version

3. Configure User Access to Docker#

Add your user account to the docker group to allow Docker execution without root privileges:

sudo usermod -aG docker $USER

After executing this command, re-authenticate by logging out and back in or by running:

newgrp docker

4. Validate Non-Privileged Docker Usage#

Confirm that Docker commands work without using sudo:

docker ps

The command should return either an empty list or the column headers.

5. Verify Docker-Compose Plugin Installation#

Check the installation of docker-compose, whether using the legacy version or the modern plugin:

docker-compose version     # For the classic (v1) version
# or
docker compose version     # For the modern (v2) plugin

If docker-compose is not available, install the required package:

sudo apt install docker-compose

Or for the modern plugin:

sudo apt install docker-compose-plugin

6. Running spkg Without sudo#

Once the configuration is complete, you may build images and compile projects with the spkg tool without requiring sudo privileges.

./spkg/spkg compose        # To build the Docker image
./spkg/spkg -p ./my_project bin    # To compile your project

Optional: Verify Docker Socket Permissions#

Ensure that the Docker socket is correctly configured with the proper group ownership and permissions:

ls -l /var/run/docker.sock

The expected output should resemble:

srw-rw---- 1 root docker ...

If the permissions are not as specified, adjust them with:

sudo chown root:docker /var/run/docker.sock
sudo chmod 660 /var/run/docker.sock