CentOS7安装docker

前言

虚拟机在进行操作前建议进行一下快照,以防安装过程中把虚拟的服务器搞乱

  1. 安装yum-utils 工具

用于增加国内yum源仓库

yum install -y yum-utils
  1. 设置 yum 仓库地址

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
执行过程:
[root@agljc ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
  1. 更新 yum 缓存

yum makecache fast #提前在本地缓存一份,用来提高搜索安装软件的速度
  1. 开始安装

yum install -y docker-ce docker-ce-cli containerd.io

docker-ce : docker 引擎,社区版。 需要 docker-ce-cli。

docker-ce-cli : docker 引擎的命令行界面,社区版

containerd.io : 守护进程 containerd。 它在 docker 包上独立工作,并且是 docker 包所必需的。

  1. docker信息查看

启动后 执行docker info可以看到如下信息

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.16.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  scan: Docker Scan (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/libexec/docker/cli-plugins/docker-scan

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 23.0.1
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 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 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-957.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.683GiB
 Name: agljc.com
 ID: 57aecf58-1bac-422c-aa33-7e1ed84094cc
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8

Docker Root Dir: /var/lib/docker

这里我们需要提前避坑,将这个默认的安装路径软链接到数据盘

systemctl stop docker #停止服务
mv /var/lib/docker/ /data/
ln -s /data/docker /var/lib/docker
ll /var/lib/docker
lrwxrwxrwx. 1 root root 12 3月   2 23:09 /var/lib/docker -> /data/docker
systemctl start docker
  1. docker操作

systemctl start docker #启动
systemctl status docker #docker服务状态查看
systemctl status docker #停止
systemctl enable docker #设置为开启自启
systemctl disable docker #禁止开机启动
  1. 测试

[root@agljc docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:6e8b6f026e0b9c419ea0fd02d3905dd0952ad1feea67543f525c73a0a790fefb
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/
此时测试成功

[root@agljc docker]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   17 months ago   13.3kB

此时我们执行上面的命令可以看到下载下来的镜像
  1. 阿里云镜像加速

找到/etc/docker/daemon.json文件并修改,添加代码如下,如果在/etc/docker下找不到daemon.json文件,可以自己新建

{
 "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com"
  ]
}
重启服务:
systemctl daemon-reload
systemctl restart docker
  1. 安装成功

此时我们已经将docker安装成功,接下来我们可以使用docker安装我们经常使用的测试环境例如MySQL、Redis、MQ等

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值