#linux #docker #homelab

Normal Docker Installation

  1. Download installer script:
    curl -fsSL get.docker.com -o get-docker.sh
  2. Execute the script:
    sh get-docker.sh
  3. Add user to docker group:
    sudo groupadd docker
    sudo gpasswd -a <user-name> docker
  4. Reboot


To update Docker rerun the get-docker.sh script.




Enabling Docker in Rootless Mode

To run Docker in rootless mode, follow the steps outlined below:

  1. Install dbus-user-session, uidmap packages
  2. If accessing via SSH, install systemd-container to switch to the local user:
    sudo apt install systemd-container
    sudo machinectl shell TheUser@<hostname>
  3. Create a non-root user and add it to the docker group User-Management (sudo usermod -aG docker)
  4. Download and execute rootless docker:
    curl -fsSL https://get.docker.com/rootless | sh
  5. Follow the instructions of script
  6. Next, in order to allow you to publish containers using ports <1024, you need to add the following line to /etc/sysctl.conf
    # Change the port number to what ever port should be the lowest port bindable for non root users.
    net.ipv4.ip_unprivileged_port_start=80
    Save the file and then reload the sysctl settings: sudo sysctl -p





Uninstall Docker

  1. Remove packages:
       sudo apt-get purge docker-ce docker-ce-cli containerd.io
  2. Remove all Docker data (images, containers, volumes):
       sudo rm -rf /var/lib/docker





General

To enable Docker to start automatically on login and to keep it running after logout:
systemctl --user start docker
systemctl --user enable docker

# Allow for docker to run in the background
sudo loginctl enable-linger $(whoami)