Centos 7.6安装Docker

我是在腾讯云轻量服务器上安装的,参考的是docker的官网的教程,链接:Install Docker Engine on CentOS | Docker DocumentationInstructions for installing Docker Engine on CentOShttps://docs.docker.com/engine/install/centos/

其中需要注意的是不能使用官方的镜像源,命令中的sudo是以管理员运行命令。安装过程如下:

1. 卸载docker的旧版本

[root@VM-4-16-centos ~]# sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

 2. yum安装gcc相关

依次执行一下两条命令

[root@VM-4-16-centos ~]# yum -y install gcc

[root@VM-4-16-centos ~]# yum -y install gcc c++

3. 安装软件包和国内的镜像仓库

分别执行下面的两条命令

[root@VM-4-16-centos ~]# sudo yum install -y yum-utils

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

4. 下载阿里云仓库

执行这个步骤是为了处理后续安装docker-ce时有些包下不了的问题

[root@VM-4-16-centos ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

5. 安装docker引擎

[root@VM-4-16-centos ~]# sudo yum install docker-ce docker-ce-cli containerd.io

6. 启动docker

[root@VM-4-16-centos ~]# sudo systemctl start docker

7. 查看docker版本

[root@VM-4-16-centos ~]# docker version

得到的版本信息如下:

[root@VM-4-16-centos ~]# docker version
# 客户端版本 20.10.16
Client: Docker Engine - Community
 Version:           20.10.16
 API version:       1.41
 Go version:        go1.17.10
 Git commit:        aa7e414
 Built:             Thu May 12 09:19:45 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
# 服务端版本 20.10.16
Server: Docker Engine - Community
 Engine:
  Version:          20.10.16
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.10
  Git commit:       f756502
  Built:            Thu May 12 09:18:08 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.4
  GitCommit:        212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
 runc:
  Version:          1.1.1
  GitCommit:        v1.1.1-0-g52de29d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

8. 执行hello-world检查docker是否启动成功

[root@VM-4-16-centos ~]# sudo docker run hello-world

执行信息如下:

# 提示本地没有hello-world镜像
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete # 远端拉取镜像
Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17
Status: Downloaded newer image for hello-world:latest
# 打出这句话就说明docker已经安装成功
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/

hello-world执行成功,表示Linux Centos 7.6上安装并启动成功了。接下来我们得配置镜像加速源

9. 腾讯云配置镜像加速源

配置镜像加速源分三步

9.1 编辑daemon.json文件

[root@VM-4-16-centos ~]# vim /etc/docker/daemon.json

9.2 往daemon.json中添加配置

按i进入编辑状态,将下面的json粘贴到daemon.json中,并保存,按ESC,然后按 :wq 保存

{
   "registry-mirrors": [
       "https://mirror.ccs.tencentyun.com"
  ]
}

9.3 重启docker

[root@VM-4-16-centos ~]# sudo systemctl restart docker

所有docker的准备工作就完成了!!!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值