Installing Docker on the latest version of Ubuntu 20+ in 2024
I. Introduction
I searched for some methods of installing docker on the Internet, but I feel that the good and the bad are mixed. Refer to GPT to sort out the solutions for installing docker from GPT4. It was actually tested to work on January 2, 2024, and it took about 7 minutes (if no errors were reported) (Down), pretty fast. Basically, it is completed in one step according to the process.
2. Steps
1. Update the software package index:
sudo apt-get update
2. The installation package allows apt to use the warehouse through HTTPS:
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
3. Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Note: I ran this for about 2 minutes, please be patient and wait for the results.
4. Set up the Docker stable version warehouse:
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Note: If you are using Ubuntu with ARM architecture, you need to change [arch=amd64] above to [arch=arm64]
5. Update the package index again:
sudo apt-get update
6. Install Docker CE:
sudo apt-get install docker-ce
7. Verify whether Docker CE is installed successfully:
sudo docker run hello-world
This command will download a test image and run it in the container. If the installation is successful, it will print a message to your terminal.
Please note that the above steps apply to most Ubuntu versions, but may differ on some older versions of Ubuntu or specific Ubuntu distributions.
Additionally, to manage Docker running as a non-root user, you may also want to add your user to the docker group:
sudo usermod -aG docker ${USER}
Once added, you will need to log out and back in, or reboot the system for the changes to take effect. This way you don't have to type sudo every time to run Docker commands.