云原生-docker(2)

105 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第18天

docker

开始安装Docker

卸载旧版本

命令:

 yum remove docker \
                   docker-client \
                   docker-client-latest \
                   docker-common \
                   docker-latest \
                   docker-latest-logrotate \
                   docker-logrotate \
                   docker-engine

示例:

 [root@iZ1608aqb7ntn9Z /]# yum remove docker \
 >                   docker-client \
 >                   docker-client-latest \
 >                   docker-common \
 >                   docker-latest \
 >                   docker-latest-logrotate \
 >                   docker-logrotate \
 >                   docker-engine
 No match for argument: docker
 No match for argument: docker-client
 No match for argument: docker-client-latest
 No match for argument: docker-common
 No match for argument: docker-latest
 No match for argument: docker-latest-logrotate
 No match for argument: docker-logrotate
 No match for argument: docker-engine
 没有软件包需要移除。
 依赖关系解决。
 无需任何处理。
 完毕!
 ​

下载依赖安装包

 yum install -y yum-utils

配置镜像仓库

 #国外的地址
 yum-config-manager \
     --add-repo \
     https://download.docker.com/linux/centos/docker-ce.repo  
 #设置阿里云的Docker镜像仓库
 yum-config-manager \
     --add-repo \
     https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 ​

示例:

 [root]# yum-config-manager \
 >     --add-repo \
 >     https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 添加仓库自:https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 ​

更新yum软件包

 yum makecache fast 
 #更新索引的时候出错,即centos8没有该参数,解决办法为:去掉fast参数
 ​

下载docker

 yum install docker-ce docker-ce-cli containerd.io   # 安装社区版
 yum install docker-ee docker-ee-cli containerd.io   # 安装企业版

一般情况下安装社区版

启动Docker 命令:

 systemctl start docker   # 启动Docker
 docker version           # 查看当前版本号,是否启动成功
 systemctl enable docker  # 设置开机自启动
 ​

示例:

 $ systemctl start docker
 
 $ docker version
 Client: Docker Engine - Community
  Version:           20.10.14
  API version:       1.41
  Go version:        go1.16.15
  Git commit:        a224086
  Built:             Thu Mar 24 01:47:44 2022
  OS/Arch:           linux/amd64
  Context:           default
  Experimental:      true
 
 Server: Docker Engine - Community
  Engine:
   Version:          20.10.14
   API version:      1.41 (minimum version 1.12)
   Go version:       go1.16.15
   Git commit:       87a90dc
   Built:            Thu Mar 24 01:46:10 2022
   OS/Arch:          linux/amd64
   Experimental:     false
  containerd:
   Version:          1.5.11
   GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
  runc:
   Version:          1.0.3
   GitCommit:        v1.0.3-0-gf46b6ba
  docker-init:
   Version:          0.19.0
   GitCommit:        de40ad0
 
 

Docker的HelloWorld 命令:

 docker run hello-world

示例:

 $ docker run hello-world
 Unable to find image 'hello-world:latest' locally  # 本地没有
 latest: Pulling from library/hello-world           # pull一个最新版
 2db29710123e: Pull complete                        # pull成功
 Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
 Status: Downloaded newer image for 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/
 ​

Docker卸载

 yum remove docker-ce docker-ce-cli containerd.io  # 卸载依赖
 rm -rf /var/lib/docker    # 删除资源  . /var/lib/docker是docker的默认工作路径

配置阿里云镜像

进入阿里云官网,搜索容器镜像服务

执行命令

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