Install the docker

Refer to the installation method on the official website:Official Website Installation Tutorial

Take Ubuntu for example:

Update the APT package index and install the package to allow APT to use the repository via HTTPS:

$ sudo apt-get update

$sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release
Copy the code

Add official Docker GPG key:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Copy the code

3. Run the following command to set the stable repository. To add a Nightly or Test repository, add a word Nightly or test (or both) stable after the word in the following command

Note: the lsb_release -cs subcommand below returns the name of your Ubuntu distribution, such as Xenial. Sometimes, in distributions like Linux Mint, you may need to change $(lsb_release-cs) to your parent Ubuntu distribution. For example, if you are using Linux Mint Tessa, you can use Bionic. Docker to offer no guarantees for untested and unsupported Ubuntu distributions.

 $ echo \
      "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Copy the code

Install the Docker engine

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Copy the code

Set up the mirror

After docker is installed, set to Alicloud image source, otherwise pull image will be very slow, refer to Alicloud image service

Take Ubuntu for example:

Use the accelerator by modifying the daemon configuration file /etc/docker/daemon.json

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

If the following error is reported when executing the docker command after the installation is complete

Ps refer to the link www.cnblogs.com/informatics…

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/json: dial Unix/var/run/docker. The sock: connect: permission deniedCopy the code

There are two solutions

  • Use sudo to obtain administrator permission. For example:
$ sudo docker ps
Copy the code
  • When the docker daemon starts, by default, the docker user group can read and write Unix sockets. Therefore, as long as the docker user group is created and the current user is added to the Docker user group, the current user has access to Unix sockets. In addition, docker related commands can be executed. The specific operations are as follows:
$ sudo groupadd docker Add docker user group
$ sudo gpasswd -a $USER docker # Add login user to docker user group
$ newgrp docker Update user group
Copy the code