A quick, TL;DR copy/paste for installing Docker on Ubuntu 22.04.

Synthesized from Docker: Install Using the Convenience Script.

  1. Figure out which version of Ubuntu (or other Linux) you’re runnin'
    cat /etc/issue
    
    Ubuntu 22.04 LTS \n \l
    
    
  2. Install a few prerequisites
    sudo apt update
    
    sudo sh -eux <<EOF
    # Install newuidmap & newgidmap binaries
    apt-get install -y uidmap
    EOF
    
  3. Use Docker’s own script to get started
    curl -fsSL https://get.docker.com -o get-docker.sh
    bash get-docker.sh
    
    dockerd-rootless-setuptool.sh install
    
  4. Set the appropriate ENVs
    DO NOT follow the ON-SCREEN instructions!
    # You should use quotes when setting `DOCKER_HOST`.
    #
    # Ex: export DOCKER_HOST='unix:///run/user/1000/docker.sock'
    DETECTED_USER_ID="$(id -u)"
    echo "export DOCKER_HOST='unix:///run/user/$DETECTED_USER_ID/docker.sock'" |
        tee -a ~/.bashrc
    
    # You probably DON'T need to change your PATH at all.
    # If you do, use quotes and put the system PATH at the end
    #
    # Ex: export PATH="$PATH:/usr/bin/"
    echo 'export PATH="$PATH:/usr/bin/"' |
        tee -a ~/.bashrc
    

Troubleshooting

Why don’t exports from dockerd-rootless-setuptool.sh don’t work (or break things that did work)?

  1. The exports are missing necessary quotes. If you have any spaces or special characters in your PATH, such as in your username, the PATH will be broken.
  2. Rather than checking the PATH resolution of docker, it always gives you a (usually) unnecessary PATH export that will place /usr/bin as the first PATH entry, which will cause locally installed programs (webi, brew, ~/bin, ~/.local)

References