Installing Docker
- It is absolutely necessary to make sure that no Docker components have already been installed on this OS:
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Add the official Docker repository to get the latest Docker version (as Debian repositories have an older version of Docker):
- Install Pre-requisites:
sudo apt update && sudo apt install ca-certificates curl gnupg
- Create a directory to store GPG keys:
sudo install -m 0755 -d /etc/apt/keyrings
- Download the Docker GPG key and store it in the new directory:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- Change the permissions of the GPG key:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
- Add the official Docker repository:
echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update from the Docker repo and install Docker:
sudo apt update && sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Test the Docker installation with a “hello world” container:
sudo docker run hello-world
- If the “hello world” container ran successfully, the following output will be displayed:
Hello from Docker! This message shows that your installation appears to be working correctly.
- Install Pre-requisites:
Create a Docker group and Add a user
NOTE: By default, Docker requires root permissions to manage containers. Therefore, a user must use sudo
with every Docker command. This can get annoying, so adding the user to the “docker” group will mitigate this.
- Create a docker group:
sudo groupadd docker
- Add the user to the group:
sudo usermod -aG docker <non_root_username>
- Log out and log back in again as the non-root user.
- Test with “hello world”:
docker run hello-world
References
https://itsfoss.com/debian-install-docker/ https://www.simplilearn.com/tutorials/docker-tutorial/how-to-install-docker-on-ubuntu https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
Docker Commands
https://docs.docker.com/engine/reference/commandline https://docs.linuxserver.io/general/docker-compose