Second, the installation of Docker

Second, the installation of Docker

One, the basic composition of Docker

Insert picture description here

Mirror (images)

The Docker image is like a template. You can use this template to create a container service. Tomcat image ===>run tomcat01 container (provides service), through this image you can create multiple containers, [the operation of the final service or the operation of the project It is in this container] This can be temporarily understood as the relationship between classes and objects in JAVA

Container

Docker uses container technology to independently run one or a group of applications and create them through mirroring.

Start, stop, delete basic commands

Repository

The warehouse is where the mirrors are stored!

The warehouse is divided into public warehouse and private warehouse

Dcoker Hub (the default is foreign), there are also many public warehouses in China, such as Alibaba Cloud... (Mirror acceleration can be configured)

Second, install Docker

Environmental preparation

  1. Need to have a certain foundation of linux
  2. Linux system is best to use CentOS7
  3. Win system may use Xshell to connect, MAC system may use a terminal connector
  4. Follow the official documentation step by step! ! ! The official documentation is very detailed

Environment view

# 系统的内核是3.10+
[root@iZhp3do4qhzu84445osa3sZ ~]# uname -r
3.10.0-1062.18.1.el7.x86_64
# 系统版本
[root@iZhp3do4qhzu84445osa3sZ ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

Docker help documentation

  1. Official document: https://www.docker.com/
  2. Choose the Linux version of Docker
  3. Choosing to install to CentOS requires CentOS version 7+ to support
# 1. 卸载旧的版本
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

# 2. 需要的安装包
yum install -y yum-utils

# 3. 设置镜像的仓库
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo  # 默认是国外的  不推荐
    
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo  # 阿里云镜像地址   推荐 
    
# 4. 更新yum !!! 不然后面可能会报错
yum makecache fase
    
# 5. 安装Docker相关的内容(这里是最新版本,如果想安装其他版本版本参考官方文档)   ce-社区版   ee-企业版
yum install docker-ce docker-ce-cli containerd.io

# 6. 启动docker
systemctl start docker

# 7. 使用docker version 查看docker是否启动成功
[root@iZhp3do4qhzu84445osa3sZ ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-109.gitcccb291.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      cccb291/1.13.1
 Built:           Tue Mar  3 17:21:24 2020
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-109.gitcccb291.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      cccb291/1.13.1
 Built:           Tue Mar  3 17:21:24 2020
 OS/Arch:         linux/amd64
 Experimental:    false
 
 # 8. 测试 hello-world
 [root@iZhp3do4qhzu84445osa3sZ ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally  # 没有寻找到hello-world镜像
Trying to pull repository docker.io/library/hello-world ... #尝试从远程仓库中寻找hello-world镜像
latest: Pulling from docker.io/library/hello-world #在远程仓库寻找到了该镜像,并且正在pull
0e03bdcc26d7: Pull complete 
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for docker.io/hello-world:latest

Hello from Docker!  #运行成功显示   相当于Docker安装成功了
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
 
 # 9. 通过docker images 查看存在的镜像
[root@iZhp3do4qhzu84445osa3sZ ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/rabbitmq          latest              7e50c60f7e3e        3 days ago          156 MB
docker.io/redis             latest              235592615444        10 days ago         104 MB
docker.io/nginx             latest              2622e6cca7eb        10 days ago         132 MB
docker.io/sonatype/nexus3   latest              57a6261043b9        2 months ago        644 MB
docker.io/hello-world       latest              bf756fb1ae65        5 months ago        13.3 kB
docker.io/mysql             5.7.25              98455b9624a9        15 months ago       372 MB 
# 卸载Docker

# 1. 卸载依赖
yum remove docker-ce docker-ce-cli containerd.io

# 2. 删除资源文件
rm -rf /var/lib/docker

# 3. Docker的默认工作路径
/var/lib/docker

3. Alibaba Cloud image acceleration

  1. Log in to your Alibaba Cloud and search for "Container Image Service"
    Insert picture description here

  2. Find the image acceleration address
    Insert picture description here

  3. Configure and use

# 1.在docker目录中新建文件夹
sudo mkdir -p /etc/docker

# 2.配置了一个阿里云的地址 (只有当前的服务器可以用,内网地址)
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    
    
  "registry-mirrors": ["https://14ukbbwv.mirror.aliyuncs.com"]
}
EOF

# 3.重启镜像
sudo systemctl daemon-reload

# 4.重启docker
sudo systemctl restart docker

# 5. 配置完毕
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo mkdir -p /etc/docker
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
    
    
>   "registry-mirrors": ["https://14ukbbwv.mirror.aliyuncs.com"]
> }
> EOF
{
    
    
  "registry-mirrors": ["https://14ukbbwv.mirror.aliyuncs.com"]
}
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo systemctl daemon-reload
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo systemctl restart docker
[root@iZhp3do4qhzu84445osa3sZ ~]# 

Fourth, the execution process of Docker

Analysis of the execution process after executing docker run hello-world

 [root@iZhp3do4qhzu84445osa3sZ ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally  # 没有寻找到hello-world镜像
Trying to pull repository docker.io/library/hello-world ... #尝试从远程仓库中寻找hello-world镜像
latest: Pulling from docker.io/library/hello-world #在远程仓库寻找到了该镜像,并且正在pull
0e03bdcc26d7: Pull complete 
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for docker.io/hello-world:latest

Hello from Docker!  #运行成功显示   相当于Docker安装成功了
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Docker is executing the flow chart of the docker run command

Insert picture description here

Docker did not find the image example

[root@iZhp3do4qhzu84445osa3sZ ~]# docker run hzbs66666666666666
Unable to find image 'hzbs66666666666666:latest' locally
Trying to pull repository docker.io/library/hzbs66666666666666 ... 
/usr/bin/docker-current: repository docker.io/hzbs66666666666666 not found: does not exist or no pull access.
See '/usr/bin/docker-current run --help'.
[root@iZhp3do4qhzu84445osa3sZ ~]# 

Five, the underlying principle

How does Dcoker work

Docker is a C/S Client-Server structure system. The Docker daemon always runs on the host and is accessed from the client through Socket!

DcoekrServer will execute this command when it receives an instruction from Docker-Client!

Insert picture description here

Each container is an independent environment and port 8080 can be opened at the same time without affecting each other!

Why Docker is better than VM block

  1. Docker has fewer abstraction layers than virtual machines
  2. Dcoker uses the host's kernel, and VM needs Guest OS.
  3. Virtualization technology data comparison:
docker LXC VM
Virtualization type OS virtualization OS virtualization Hardware virtualization
performance = Physical machine performance = Physical machine performance 5%-20% performance loss
Isolation NS isolation NS isolation Strong
Qos Ggroup weak Ggroup weak Strong
safety in difference Strong
GuestOS Only supports Linux Only supports Linux All
Transferable Strong weak Strong

Guess you like

Origin blog.csdn.net/qq_39381775/article/details/106929161