Install docker engine¶
You can find the official doc here.
Remove old version¶
Uninstall any such older versions before attempting to install a new version:
sudo apt-get remove docker docker-engine docker.io containerd runc
Images, containers, volumes, and networks stored in /var/lib/docker/ aren’t automatically removed when you uninstall Docker. If you want to start with a clean installation, and prefer to clean up any existing data, you need to remove them too.
Install via apt repository¶
This procedure works for Debian on x86_64 / amd64, armhf, arm64, and Raspbian.
Step1. Set up prerequisites¶
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
Step2. Add GPG Key¶
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Step3. Set up repository¶
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step4. Install Docker Engine¶
# update apt package index
sudo apt-get update
# install the latest version of docker engine, docker client and docker compose
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose
Step5. Test Docker engine¶
Below command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
sudo docker run hello-world
Step 5. Post install config¶
You have now successfully installed and started Docker Engine. The docker user group exists but contains no users, which is why you’re required to use sudo to run Docker commands. If you want to allow non-privileged users to run Docker commands, you need to do following config.
# check if the docker group exist or not
cat /etc/group | grep -i "docker"
# if you see below line, it's good
docker:x:996:
# if not, you can create the group
sudo groupadd docker
# add current user to the group, you can replace $USER with any user id
sudo usermod -aG docker $USER
# now you need to logout and relogin to see the effect
# If you’re running Linux in a virtual machine, it may be necessary to
# restart the virtual machine for changes to take effect.
# relogin
su -l $USER
# check your docker group
id
# you should see below output
uid=1000(pliu) gid=1000(pliu) groups=1000(pliu),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),108(netdev),996(docker)
# now you can run docker command without sudo
docker image list
# You should see
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 13 months ago 13.3kB