Devnet
Docker
Install

Prerequisites

Note: If you use ufw or firewalld to manage firewall settings, note that when you expose container ports using Docker, these ports bypass your firewall rules. For more information, see Docker and ufw.

OS Requirements

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:

  • Ubuntu Mantic 23.10
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)

Docker Engine for Ubuntu works with various architectures including x86_64 (or amd64), armhf, arm64, s390x, and ppc64le (ppc64el).

Uninstall Old Versions

Before installing Docker Engine, uninstall any conflicting packages. These unofficial packages need removal:

  • docker.io
  • docker-compose
  • docker-compose-v2
  • docker-doc
  • podman-docker

Additionally, uninstall containerd or runc if previously installed to prevent conflicts.

Run the following command to remove conflicting packages:

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Installation Methods

You can install Docker Engine in several ways:

  1. Docker Engine is bundled with Docker Desktop for Linux.
  2. Set up and install Docker Engine from Docker's apt repository.
  3. Manual installation and manual upgrade management.
  4. Use a convenience script (recommended only for testing and development).

Install Using the Apt Repository

Before installing Docker Engine, set up Docker's apt repository. Follow these steps:

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get 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:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Install Docker Packages

To install the latest version, use:

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

Verify the installation:

sudo docker run hello-world
  • add user to docker group
sudo usermod -aG docker $USER
  • confirm we are now in the docker group
groups

-- restart the service

sudo service docker restart

If you're still encountering "permission denied" issues despite being added to the docker group, there might be some additional troubleshooting steps to consider:

1. Group Membership Update:

Ensure that your group membership has been updated properly. Sometimes changes to group membership might not take effect immediately. You can log out and log back in again to ensure that the changes are applied to your session.

2. Check Docker Socket Permissions:

Verify the permissions of the Docker socket file (/var/run/docker.sock). The Docker daemon communicates with client applications through this socket. Run the following command to check its permissions:

ls -l /var/run/docker.sock

Ensure that the permissions allow members of the docker group to access the socket. The output should resemble something like this:

srw-rw---- 1 root docker 0 Mar 23 09:00 /var/run/docker.sock

If the permissions are not set correctly, you can adjust them using the chmod command:

sudo chmod 660 /var/run/docker.sock

3. Restart Docker Service:

Restart the Docker service to ensure that any recent changes, including group membership updates, are applied:

sudo service docker restart

4. Verify Group Membership:

Double-check that your user is indeed a member of the docker group by running:

groups $USER

Ensure that docker is listed among the groups.

5. Debugging with docker Command:

Try running a Docker command with debugging output to get more insight into the issue:

docker --debug ps

The debug output might provide additional information about the permission denied error.

6. Reboot:

If all else fails, you might consider rebooting your system. Sometimes a reboot can resolve unexpected issues with group permissions and services.

7. Check SELinux or AppArmor:

If you're using SELinux or AppArmor, ensure that they are not blocking Docker's access. Check their respective configurations and logs for any relevant messages.

By following these troubleshooting steps, you should be able to diagnose and resolve the "permission denied" issue with Docker.