-
Notifications
You must be signed in to change notification settings - Fork 0
Installing Docker correctly
There are a few different documented ways of installing Docker, however none (even the official way) factor in subtle differences in distributions. The way I tend to go for, and the way that is guaranteed to work with both k.t.d and k.d.d is as follows.
The first step is to add the GPG key and apt lists. The best way to do this is with lsb_release:
sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release -yWith lsb_release installed, we can automate the fetching and installing of the key with:
export DPKG_ARCH="$(dpkg --print-architecture)"
export LSB_ID="$(bash -c 'lsb_release -is | tr [:upper:] [:lower:]')"
export LSB_CODENAME="$(bash -c 'lsb_release -cs | tr [:upper:] [:lower:]')"
sudo mkdir -p /usr/share/keyrings
curl -fsSL https://download.docker.com/linux/${LSB_ID}/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker.gpg >/dev/null
echo "deb [arch=${DPKG_ARCH} signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/${LSB_ID} ${LSB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullOnce the key and list is added, you can install Docker:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -yTo wrap up, add the current user to the docker group:
sudo usermod -aG docker my-userRestart your terminal, and then run the hello-world docker to test all is well:
docker run hello-worldIf the installation went successfully, you should see the following in your terminal:
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/Congratulations! Docker is now installed correctly, and ready to work.