Docker容器引擎的安装部署

跟我一步一步部署docker容器                作者:张岩峰,转载请注明出处     笔名:云烟旧梦

目录:

        1、基础环境检查

        2、安装epel源

        3、安装官方Docker源

        4、安装最新版本Docker并配置

        5、启动Docker

        6、检查docker配置及启动情况

        7、启动第一个Docker容器


1、基础环境检查

        #检查环境

        [root@localhost ~]# uname -a

       Linux localhost.localdomain 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

        [root@localhost ~]# cat /etc/redhat-release 

        CentOS Linux release 7.8.2003 (Core)


        #关闭防火墙和SELinux

        setenforce 0

        sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config 

        systemctl stop firewalld

        systemctl disable firewalld


        #检查网络

        [root@localhost ~]# ping www.baidu.com -c 2

        PING www.a.shifen.com (110.242.68.3) 56(84) bytes of data.

        64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=52 time=24.2 ms

        64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=52 time=27.3 ms


        #检查内存

        [root@localhost ~]# free -m

             total     used    free      shared  buff/cache  available

            Mem:  981      231     102         7         647         595

            Swap: 2047     0        2047


2、安装epel源

        安装epel源

        yum -y install wget

        cd /etc/yum.repos.d/

        wget http://mirrors.aliyun.com/repo/epel-7.repo

        wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

        yum clean all

        yum makecache

        yum -y install lrzsz net-tools epel-release


        这里可以看到epel源里也有docker1.13.1

        [root@localhost ~]# yum list docker --show-duplicates

        Loaded plugins: fastestmirror

        Repository epel is listed more than once in the configuration

        Repository epel-debuginfo is listed more than once in the configuration

        Repository epel-source is listed more than once in the configuration

        Loading mirror speeds from cached hostfile

         * c7-media: 

        Available Packages

        docker.x86_64    2:1.13.1-102.git7f2769b.el7.centos   extras


3、安装官方Docker源

        安装docker-ce源:

        [root@localhost ~]# yum install yum-utils -y

        [root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo


        这里可以看到docker-ce源里的docker镜像了

        [root@localhost ~]# yum list docker-ce --show-duplicates

        Loaded plugins: fastestmirror

        Repository epel is listed more than once in the configuration

        Repository epel-debuginfo is listed more than once in the configuration

        Repository epel-source is listed more than once in the configuration

        Loading mirror speeds from cached hostfile

         * c7-media: 

        Available Packages

        docker-ce.x86_64   3:19.03.15-3.el7  docker-ce-stable

        docker-ce.x86_64   3:20.10.5-3.el7   docker-ce-stable


4、安装最新版本Docker并配置

        [root@localhost ~]# yum -y install docker-ce

        [root@localhost ~]# mkdir /etc/docker

        [root@localhost ~]# cd /etc/docker/

        [root@localhost docker]# vi /etc/docker/daemon.json

        {

         "graph": "/data/docker",

          "storage-driver": "overlay2",

          "insecure-registries": ["registry.access.redhat.com","quay.io"],

          "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],

          "bip": "172.43.101.1/24",

          "exec-opts": ["native.cgroupdriver=systemd"],

          "live-restore": true

        }

        

        内容说明:

        {

          "graph": "/data/docker",     #docker工作目录

          "storage-driver": "overlay2",   #存储驱动

          "insecure-registries": ["registry.access.redhat.com","quay.io"],  # 不安全的仓库

          "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],  # 加速镜像

          "bip": "172.43.101.1/24",   #docker的网络,尽量要与宿主机有个对照关系

          "exec-opts": ["native.cgroupdriver=systemd"],  #cgroup的类型

          "live-restore": true  #让docker容器不依懒docker引擎的死与活

        }


5、启动Docker

        [root@localhost ~]# systemctl enable docker.service

        [root@localhost ~]# systemctl start docker.service

        

        [root@localhost ~]# docker version

        Client: Docker Engine - Community

         Version:           20.10.5

         API version:       1.41

         Go version:        go1.13.15

         Git commit:        55c4c88

         Built:             Tue Mar  2 20:33:55 2021

         OS/Arch:           linux/amd64

         Context:           default

         Experimental:      true

        

        Server: Docker Engine - Community

         Engine:

          Version:          20.10.5

          API version:      1.41 (minimum version 1.12)

          Go version:       go1.13.15

          Git commit:       363e9a8

          Built:            Tue Mar  2 20:32:17 2021

          OS/Arch:          linux/amd64

          Experimental:     false

         containerd:

          Version:          1.4.4

          GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e

         runc:

          Version:          1.0.0-rc93

          GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec

         docker-init:

          Version:          0.19.0

          GitCommit:        de40ad0


6、检查docker配置及启动情况

        [root@localhost ~]# docker info

        Client:

         Context:    default

         Debug Mode: false

         Plugins:

          app: Docker App (Docker Inc., v0.9.1-beta3)

          buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)


        Server:

         Containers: 0

          Running: 0

          Paused: 0

          Stopped: 0

         Images: 0

         Server Version: 20.10.5    #Docker版本

         Storage Driver: overlay2    #存储驱动

          Backing Filesystem: xfs    #文件系统

          Supports d_type: true

         Native Overlay Diff: true

         Logging Driver: json-file

         Cgroup Driver: systemd

         Cgroup Version: 1

         Plugins:

          Volume: local

          Network: bridge host ipvlan macvlan null overlay

          Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog

         Swarm: inactive

         Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc

         Default Runtime: runc

         Init Binary: docker-init

         containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e

         runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec

         init version: de40ad0

         Security Options:

          seccomp

           Profile: default

         Kernel Version: 3.10.0-1127.el7.x86_64

         Operating System: CentOS Linux 7 (Core)

         OSType: linux

         Architecture: x86_64

         CPUs: 1

         Total Memory: 981.9MiB

         Name: localhost.localdomain

         ID: 6WQE:UXYL:LED5:IJM5:FEV4:CEHF:DFLP:VFIE:O262:PK3Y:TADB:AD7H

         Docker Root Dir: /data/docker

         Debug Mode: false

         Registry: https://index.docker.io/v1/

         Labels:

         Experimental: false

         Insecure Registries:

          registry.access.redhat.com

          quay.io

          127.0.0.0/8

         Registry Mirrors:

         https://q2gr04ke.mirror.aliyuncs.com/

         Live Restore Enabled: true


7、启动第一个Docker容器

          [root@localhost ~]# docker run hello-world

          Unable to find image 'hello-world:latest' locally  #<==在本地找不到一个叫hello-world的容器

          latest: Pulling from library/hello-world

          0e03bdcc26d7: Pull complete 

          Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d  #<==分析MD5是否正确

          Status: Downloaded newer image for hello-world:latest  #<==下载完成,下载了一个最新的hello-world:latest镜像。


          Hello from 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/


          对上面的四步解释:

          1、客户端连接到了服务端

          2、服务端发现本地没有hello-world镜像,然后从github上拉了下来。

          3、然后根据这个镜像作为模板,把这个hello-world容器起来了。

          4、Docker守护进程将输出传输到Docker客户端,然后发送到你的终端。

上一篇:No package vconfig available安装软件提示找不到可用包linux,linux如何安装vconfig


下一篇:CentOS 6 安装Docker