Detailed tutorial on installing docker on ubuntu and configuring Alibaba Cloud image acceleration

ubuntu environment:

Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial The
following command can check the ubuntu version:

sudo lsb_release -a

Reference installation tutorial: docker official website:  https://docs.docker.com/engine/install/

B-station mad god docker tutorial video: https://www.bilibili.com/video/BV1og4y1q7M4?p=6 , note that this video uses CenterOs as an example to install docker

Here is mainly the docker official website tutorial

1. Uninstall the old version of docker first

If you have not installed the docker ubuntu system, you can ignore it.

The official website gave a command at the beginning:

sudo apt-get remove docker docker-engine docker.io containerd runc

After practice, this command alone cannot uninstall docker, and the following two commands are needed:

(1) Uninstall Docker Engine, CLI and Containerd software packages:

sudo apt-get purge docker-ce docker-ce-cli containerd.io

(2) The images, containers, volumes or custom configuration files on the host will not be deleted automatically. To delete all images, containers, and volumes, manually delete:

sudo rm -rf /var/lib/docker

The official website tutorial also has a detailed uninstall tutorial https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine

After uninstalling the old version of docker clean, you can install docker next

2. Use the repository (repository) to install

(1) Update the aptpackage index and install the package to allow the aptrepository to be used via HTTPS:

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

(2) Add Docker's official GPG key:

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

sudo apt-key fingerprint 0EBFCD88

(3) Use the following command to set up a stable repository.

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable nightly test"

3. Install docker (Docker Engine)

sudo apt-get install docker-ce docker-ce-cli containerd.io

docker-ce: means this is the docker community edition

Enterprise version is docker-ee

The default here is to install the latest version of docker. If you want to install a specific version of Docker Engine, please refer to https://docs.docker.com/engine/install/ubuntu/

At this point, docker has been installed, and then test whether it has been installed successfully.

4. hello-world Verify that Docker is installed correctly by running the image

Step 3 After installing docker, docker has been automatically started, so we don't need to start it manually. It seems to be started manually in CenterOS.

CenterOS manually start the docker command:

systemctl start docker

So run helloworld directly:

docker run hello-world

Seeing the above output information, it means that docker has been installed successfully.

Here is an explanation of the running sequence of docker, the more important knowledge points.

First of all, the docker we just installed does not have the hello-world image, so the first line in the screenshot says that this image cannot be found locally, and the second line executes a pull to pull the hello-word image back from the Internet (dockerhub). So it can be seen that the order in which the docker container runs is

(1). First search for the corresponding mirror (such as hello-world) in the local host docker warehouse, if you can’t find it, go to the online mirror source (dockerhub, Alibaba Cloud) to search

(2) Searched for the online mirror source (dockerhub, Alibaba Cloud), and then executed the docker pull command to pull the hello-world image from the mirror source to the local host warehouse

(3) Then create a container and run it with the local host hello-world image.

5. Configure Alibaba Cloud image acceleration

After installing docker, the default is the dockerhub mirror source, which is a foreign website, and the download speed is very slow when pulling the mirror. Therefore, we need to use domestic mirror sources. Famous domestic mirror sources are Alibaba Cloud and NetEase Cloud. So configure Alibaba Cloud image acceleration below.

(1) Use your own Alibaba Cloud account to log in

(2) Find the container mirroring service and click to enter

(3) Click on the management console

(4) Enter here for the first time using Alibaba Cloud, you need to set the Registry login password

(5) Find the image acceleration address

(6) Configuration and use

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://w102lieg.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

It is very strange that my ubuntu reported the same error when executing these two commands. If you have a big brother who understands the reason, please guide us in the comments, thank you!

sudo systemctl daemon-reload

sudo systemctl restart docker

So use the following command to restart the docker service

sudo service docker restart

Guess you like

Origin blog.csdn.net/Thanours/article/details/108923267