Install Docker based on Ubuntu

What is Docker

Docker is a virtualized container engine that completely uses the sandbox isolation mechanism, which has great advantages over traditional VM virtual machines.

"Linux Install Docker"

"Linux Install Docker"

The difference between traditional virtual machine (VM) and virtualized container (Docker):

  • Traditional VM virtual machines cannot share resources. For example, a Linux operating system with 4GB of memory is installed in VMWare, which means that the Linux system uses the fixed 4GB of memory in the host and cannot share the resources with the host or other virtual systems. , May cause resource waste or resource overflow
  • Docker makes up for the shortcomings of traditional VM virtual machines. Each virtualized operating system can share resources with each other, solving a series of problems such as resource overflow or resource waste.

Docker main concepts

Docker image (Image)

  • The operating system is divided into kernel and user space. For Linux, after the kernel starts, it will mount the root file system to provide user space support. The Docker image (Image) is equivalent to a root file system
  • The Docker image is a special file system. In addition to providing the programs, libraries, resources, and configuration files required by the container runtime, it also contains some configuration parameters (such as environment variables, users, etc.) prepared for the runtime.

Docker container (Container)

  • The relationship between Docker images and Docker containers is like classes and objects in object-oriented programming , and images are statically defined
  • A container is an entity at the time of image runtime, which can be created, started, stopped, deleted, suspended, etc.
  • The process in the container is running in an isolated environment, and it is used as if operating in a system independent of the host. This feature makes the application encapsulated in the container safer than running directly on the host.

Docker warehouse (Registry)

  • After the image is built, a single command can be run on the current host, but if you want to use this image on other servers, you need a centralized storage warehouse-that is, the Docker warehouse
  • Public Docker Registry: Registry public services most commonly used is the official Docker Hub , but access will be slower in the country, and some domestic cloud service providers to provide a mirror for Docker Hub services, and common are Ali cloud , DaoCloud accelerator, It will be much faster than downloading directly from Docker Hub
  • Private Docker Registry: You can build a private Docker Registry locally. Docker officially provides the Docker Registry image, which can be used directly as a private Registry service

Install Docker

Method 1: Automatic installation using script

$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun

After executing these two lines of commands, the script will automatically complete all preparations and install Docker CE Edge in the system.

Method 2: Install with APT

Install some necessary system tools

$ sudo apt-get update
$ sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

Install GPG Certificate

$ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

Write software source information

$ sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

Update software source

$ sudo apt-get -y update

Install Docker CE

$ sudo apt-get -y install docker-ce

Join the Docker user group

After installation, by default, Docker commands use Unix sockets to communicate with the Docker engine. Only root users and users in the Docker group can access the Docker engine Unix sockets. Generally, root users are not directly used on Linux systems. Therefore, it is better to add users who need to use Docker to the Docker user group.

  • Create a Docker user group
$ sudo groupadd docker
  • Add users to the Docker user group
$ sudo usermod -aG docker $USER

This article first appeared on: https://antoniopeng.com

Configure Image Accelerator

Since downloading images from Docker Hub in China is sometimes very slow, you can configure an image accelerator provided by a domestic cloud service provider:

Alibaba Cloud Mirror Accelerator

Add mirror accelerator

  • Login to Alibaba Cloud
  • Go to Container Image Service Console> Image Accelerator
  • Add mirror accelerator
  • Copy the accelerator address, as shown below
    Insert picture description here

Ubuntu 14.04, Debian 7 Wheezy system configuration

  • Edit docker configuration file

    $ sudo nano /etc/default/docker
    
  • Add the following code

    DOCKER_OPTS="--registry-mirror=<镜像加速器地址>"
    
  • Restart the Docker service

    $ sudo service docker restart
    

Ubuntu 16.04+, Debian 8+, CentOS 7 system configuration

  • Edit the daemon.json configuration file

    $ sudo nano /etc/docker/daemon.json
    
  • Add the following code

    {
      "registry-mirrors": [
        "<镜像加速器地址>"
      ]
    }
    
  • Restart the Docker service

    $ sudo systemctl daemon-reload
    $ sudo systemctl restart docker
    
  • Check if the accelerator is effective

    $ docker info
    

    See the output below, indicating that the image accelerator is successfully configured

    Registry Mirrors:
     <镜像加速器地址>
    
  • Author: Chao Peng

  • This article first appeared on my personal blog: https://antoniopeng.com/2019/07/06/docker/%E5%9F%BA%E4%BA%8EUbuntu%E5%AE%89%E8%A3%85Docker/

  • Copyright notice: All articles in this blog use the CC BY-NC-SA 4.0 license agreement unless otherwise stated. Reproduced please specify from Chao Peng | Blog !

Guess you like

Origin www.cnblogs.com/antoniopeng/p/12687302.html