第二章 Docker安装

第二章 Docker安装

Linux安装docker

1、查看版本信息是否符合安装条件:
  • 用户使用linux为64位操作系统;
  • 系统内核版本至少在3.10以上。
[root@chenyujie ~]# uname -a
Linux chenyujie 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@chenyujie ~]# uname -r
3.10.0-1160.el7.x86_64
2、yum更新

使用Root权限登录 Centos。确保yum包更新到最新。

[root@chenyujie ~]# yum update
3、卸载原有docker
[root@chenyujie ~]# yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

4、安装docker(使用阿里云yum安装)
  • 安装必要工具:
[root@chenyujie ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已安装:
  yum-utils.noarch 0:1.1.31-54.el7_8                                                   

作为依赖被安装:
  python-kitchen.noarch 0:1.1.1-5.el7                                                  

完毕!
  • 添加软件源信息
[root@chenyujie ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 换阿里镜像源
[root@chenyujie ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
  • 更新并安装docker-CE
[root@chenyujie ~]# yum makecache fast
[root@chenyujie ~]# yum -y install docker-ce

已安装:
  docker-ce.x86_64 3:25.0.3-1.el7                                                      

作为依赖被安装:
  containerd.io.x86_64 0:1.6.28-3.1.el7                                                
  docker-buildx-plugin.x86_64 0:0.12.1-1.el7                                           
  docker-ce-cli.x86_64 1:25.0.3-1.el7                                                  
  docker-ce-rootless-extras.x86_64 0:25.0.3-1.el7                                      
  docker-compose-plugin.x86_64 0:2.24.6-1.el7                                          

完毕!

  • 开启docker服务设置开机自启
[root@chenyujie ~]# start docker.service
[root@chenyujie ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
  • 安装校验
[root@chenyujie ~]# docker version
Client: Docker Engine - Community
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:17:10 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:16:08 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@chenyujie ~]# 
  • 下载hello-world
[root@chenyujie ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
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加速器(阿里云)
  • 可能出现问题:无法拉取hello-world

  • [root@chenyujie ~]# docker run hello-world
    Unable to find image 'hello-world:latest' locally
    Trying to pull repository docker.io/library/hello-world ... 
    /usr/bin/docker-current: missing signature key.
    See '/usr/bin/docker-current run --help'.
    

意思是docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取到镜像。

  • 异常原因:

​ 这是因为docker服务器在国外,基于网速与“和谐墙”的问题,所以我们在国内操作国外镜像可能无法正常拉取,这需要我们为docker设置国内的阿里云镜像加速器。

  • 解决方法:

    添加阿里云镜像:

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

 { 
 "registry-mirrors": ["https://v97vyodn.mirror.aliyuncs.com"] 
 }
 
 #systemctl restart docker
 #sudo systemctl status docker

重新拉取即可成功

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值