环境说明
- 检查 Linux 内核版本,Docker 要求CentOS 系统的内核版本高于3.10,如下所示 内核版本为 3.10.0-327.el7
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# uname -r
3.10.0-327.el7.x86_64
[root@localhost ~]#
[root@localhost ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.2.1511 (Core)
Release: 7.2.1511
Codename: Core
[root@localhost ~]#
Docker 卸载
查看安装包
[root@localhost docker]# yum list installed |grep docker
docker.x86_64 2:1.13.1-68.gitdded712.el7.centos @extras
docker-client.x86_64 2:1.13.1-68.gitdded712.el7.centos @extras
docker-common.x86_64 2:1.13.1-68.gitdded712.el7.centos @extras
[root@localhost docker]#
删除安装包
[root@localhost docker]# yum -y remove docker.x86_64
...
[root@localhost docker]# yum -y remove docker-client.x86_64
...
[root@localhost docker]# yum -y remove docker-common.x86_64
...
[root@localhost docker]# yum list installed |grep docker
[root@localhost docker]#
删除docker 镜像
- /var/lib/docker 是 Docker 安装后默认的容器和镜像目录,也要一并删除
[root@localhost lib]# rm -rfv /var/lib/docker/
...
[root@localhost docker]#
Docker 安装
检查安装情况
- 如下所示当前服务器没有安装 Docker,而且提供了安装包可以安装,是一个 1.13 版本的 Docker。
[root@localhost ~]# yum list docker
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.zju.edu.cn
* updates: centos.ustc.edu.cn
可安装的软件包
docker.x86_64 2:1.13.1-68.gitdded712.el7.centos extras
[root@localhost ~]#
yum update
- 使用 yum 安装 Docker 之前,使用 yum update 命令更新所有软件。
- 如下所示 已经全部更新完了,自己第一次在虚拟机上安装 docker 的时候,就是因为没有做更新,导致安装后 Docker 启动失败
[root@localhost ~]# yum update
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.zju.edu.cn
* updates: centos.ustc.edu.cn
No packages marked for update
[root@localhost ~]#
安装 Docker
- 没有安装时则使用 “ yum -y install docker ” 进行安装
[root@localhost ~]# yum -y install docker
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
http://repo.mysql.com/yum/mysql-connectors-community/el/7/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to repo.mysql.com:80; 拒绝连接"
正在尝试其它镜像。
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql80-community | 2.5 kB 00:00:00
updates | 3.4 kB 00:00:00
extras/7/x86_64/primary_db FAILED =======================================================- ] 154 kB/s | 4.2 MB 00:00:02 ETA
http://mirrors.shu.edu.cn/centos/7.5.1804/extras/x86_64/repodata/ad9f6f003e216bbc4e9c7d6579adaa4d35e7a2d2ee3eca44d683069bb7e9ac59-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.shu.edu.cn:80; Connection refused"
正在尝试其它镜像。
(1/2): extras/7/x86_64/primary_db | 174 kB 00:00:02
(2/2): updates/7/x86_64/primary_db | 4.3 MB 00:00:24
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.zju.edu.cn
* updates: centos.ustc.edu.cn
正在解决依赖关系
........
作为依赖被安装:
audit-libs-python.x86_64 0:2.8.1-3.el7 checkpolicy.x86_64 0:2.5-6.el7
container-selinux.noarch 2:2.66-1.el7 container-storage-setup.noarch 0:0.10.0-1.gitdf0dcd5.el7
docker-client.x86_64 2:1.13.1-68.gitdded712.el7.centos docker-common.x86_64 2:1.13.1-68.gitdded712.el7.centos
libcgroup.x86_64 0:0.41-15.el7 libseccomp.x86_64 0:2.3.1-3.el7
libsemanage-python.x86_64 0:2.5-11.el7 oci-register-machine.x86_64 1:0-6.git2b44233.el7
oci-systemd-hook.x86_64 1:0.1.16-1.git05bd9a0.el7 oci-umount.x86_64 2:2.3.3-3.gite3c9055.el7
policycoreutils-python.x86_64 0:2.5-22.el7 python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-2.el7 skopeo-containers.x86_64 1:0.1.31-1.dev.gitae64ff7.el7.centos
yajl.x86_64 0:2.0.4-4.el7
作为依赖被升级:
audit.x86_64 0:2.8.1-3.el7 audit-libs.x86_64 0:2.8.1-3.el7 libsemanage.x86_64 0:2.5-11.el7 policycoreutils.x86_64 0:2.5-22.el7
selinux-policy.noarch 0:3.13.1-192.el7_5.4 selinux-policy-targeted.noarch 0:3.13.1-192.el7_5.4
完毕!
[root@localhost ~]#
查看版本
- 使用 docker version 查看安装情况,如下所示表示安装成功
[root@localhost ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
Go version: go1.9.4
Git commit: dded712/1.13.1
Built: Tue Jul 17 18:34:48 2018
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
Go version: go1.9.4
Git commit: dded712/1.13.1
Built: Tue Jul 17 18:34:48 2018
OS/Arch: linux/amd64
Experimental: false
[root@localhost ~]#
启动 Docker
- docker 程序安装完成后自己本身就是一个服务,类似于 mysql 安装后自己也是一个服务
- 对于服务的管理操作起来更加简单,可以使用 Linux 的 “ service ” 命令,对于 CentOS 7.0 及以上的版本建议使用 “systemctl ” 命令
- 使用 systemctl start docker 命令进行启动;systemctl status docker 可以查看服务运行的状态
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2018-08-15 16:15:22 CST; 21s ago
Docs: http://docs.docker.com
Main PID: 1357 (dockerd-current)
CGroup: /system.slice/docker.service
├─1357 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=...
└─1361 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /v...
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.255155090+08:00" level=warning msg="overlay2: the backing xfs filesystem is format...
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.346695806+08:00" level=info msg="Graph migration to content-addressabilit... seconds"
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.347539731+08:00" level=info msg="Loading containers: start."
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.384094857+08:00" level=info msg="Firewalld running: true"
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.563394713+08:00" level=info msg="Default bridge (docker0) is assigned wit... address"
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.718830358+08:00" level=info msg="Loading containers: done."
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.730741023+08:00" level=info msg="Daemon has completed initialization"
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.730761099+08:00" level=info msg="Docker daemon" commit="dded712/1.13.1" g...on=1.13.1
8月 15 16:15:22 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.744954709+08:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
查看运行状态
- 如上所示,使用 “ systemctl status docker ” 命令即可查看
停止 Docker
- 使用 systemctl stop docker 命令停止 Docker
[root@localhost ~]# systemctl stop docker
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead) since 三 2018-08-15 16:57:07 CST; 3s ago
Docs: http://docs.docker.com
Process: 1357 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=0/SUCCESS)
Main PID: 1357 (code=exited, status=0/SUCCESS)
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.563394713+08:00" level=info msg="Default bridge (docker0) is assigned wit... address"
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.718830358+08:00" level=info msg="Loading containers: done."
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.730741023+08:00" level=info msg="Daemon has completed initialization"
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.730761099+08:00" level=info msg="Docker daemon" commit="dded712/1.13.1" g...on=1.13.1
8月 15 16:15:22 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
8月 15 16:15:22 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:15:22.744954709+08:00" level=info msg="API listen on /var/run/docker.sock"
8月 15 16:57:06 localhost.localdomain systemd[1]: Stopping Docker Application Container Engine...
8月 15 16:57:06 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:57:06.560614849+08:00" level=info msg="Processing signal 'terminated'"
8月 15 16:57:06 localhost.localdomain dockerd-current[1357]: time="2018-08-15T16:57:06.564901422+08:00" level=info msg="stopping containerd after receiving terminated"
8月 15 16:57:07 localhost.localdomain systemd[1]: Stopped Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
开机启动 Docker
- 因为 Docker 本身是服务,做成开机自启就方便多了,使用命令:systemctl enable docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]#