Installing Docker on the latest version of Ubuntu 20+ in 2024

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.
Insert image description here

2. Steps

1. Update the software package index:

sudo apt-get update

Insert image description here

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

Insert image description here

3. Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Insert image description here
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]
Insert image description here

5. Update the package index again:

sudo apt-get update

Insert image description here

6. Install Docker CE:

sudo apt-get install docker-ce

Insert image description here

7. Verify whether Docker CE is installed successfully:

sudo docker run hello-world

Insert image description here

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}

Insert image description here
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.

Guess you like

Origin blog.csdn.net/qq_51116518/article/details/135351897