一, 概述
Docker 在 1.13 版本之后, 从 2017 年的 3 月 1 日开始, 版本命名规则变为如下:
项目 | 说明 |
版本格式 | YY.MM |
Stable | 每个季度发行 |
Edge 版本 | 每个月发行 |
同时 Docker 划分为 CE 和 EE.CE 即社区版(免费, 支持后期三个月),EE 即企业版, 强调安全, 付费使用.
本实验虚拟机 CentOS7, 采用阿里云 yum 源安装
二, 安装 Docker CE 先决条件
官方各个版本安装文档: https://docs.docker.com/install/ https://docs.docker.com/install/
系统要求
Docker CE 支持 64 位版本 CentOS 7, 并且要求内核版本不低于 3.10.CentOS 7 满足最低内核的要求, 但由于内核版本比较低, 部分功能 (如 overlay2 存储层驱动) 无法使用, 并且部分功能可能不太稳定.
查看系统内核版本
- [root@linux-node1 ~]# cat /proc/version
- Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
- [root@linux-node1 ~]# uname -a
- Linux linux-node1.example.com 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
- [root@linux-node1 ~]#
卸载旧版本
老版本的 Docker 被称为 docker 或 docker-engine. 如果安装了它们, 请卸载他们以及相关的依赖项.
$ sudo yum remove docker \
- docker-client \
- docker-client-latest \
- docker-common \
- docker-latest \
- docker-latest-logrotate \
- docker-logrotate \
- docker-selinux \
- docker-engine-selinux \
- docker-engine
- [root@linux-node1 ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
- Loaded plugins: fastestmirror
- 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-selinux
- No Match for argument: docker-engine-selinux
- No Match for argument: docker-engine
- No Packages marked for removal
示例一
如上示例一中所示报告说没有安装这些软件包, 就 OK 了.
/var/lib/docker / 包括图像, 容器, 卷和网络的内容将被保留, 现在调用 Docker CE 包 docker-ce.
三, 安装 Docker CE
使用存储库进行安装
首次在新的主机上安装 Docker CE 之前, 需要设置 Docker 存储库, 之后, 您可以从存储安装和更新 Docker.
设置存储库
安装所需要的包. yum-utils 提供了 yum-config-manager, 并
device-mapper-persistent-data
和 lvm2 由需要 devicemapper 存储驱动程序.
[root@linux-node1 ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
使用以下命令设置稳定的存储库
- Complete!
- [root@linux-node1 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
如果需要使用最新版的 Docker CE 使用以下命令(默认处于禁用状态)
yum-config-manager --enable docker-ce-edge
如果使用测试版本的 Docker CE 请使用以下命令(默认处于禁用状态)
yum-config-manager --enable docker-ce-test
可以通过使用该标志运行命令来禁用
边缘或测试
存储库 . 要重新启用它, 请使用标志. 以下命令禁用边缘存储库.
- yum-config-manager--disable--enable
- yum-config-manager --disable docker-ce-edge
注意: 从 Docker 17.06 开始, 稳定版本也被推到边缘并测试版本库.
yum 安装 Docker
- [root@linux-node1 ~]# yum -y install docker-ce
- Installed:
- docker-ce.x86_64 0:18.03.1.ce-1.el7.centos
- Dependency Installed:
- container-selinux.noarch 2:2.55-1.el7
启动 Docker
[root@linux-node1 ~]# systemctl start docker
查看 Docker 运行状态
[root@linux-node1 ~]# systemctl status docker
测试 Docker 是否安装正确
- [root@linux-node1 ~]# docker run hello-world
- Unable to find image 'hello-world:latest' locally
- latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
- 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/engine/userguide/
四, 创建 docker 用户组(此操作可以不执行)
docker 守护程序绑定到一个 Unix 套接字而不是 TCP 端口. 默认情况下, Unix 套接字由 root 用户拥有, 其它用户只能使用 sudo 来访问它, 该 docker 守护进程始终运行的 root 用户.
处于安全考虑, 一般 Linux 系统上不会直接使用 root 用户, 因此, 更好的做法是将需要使用 docker 的用户加入 docker 用户组. 当 docker 守护进程启动时, 它使得 Unix 套接字的所有权可以被 docker 组读 / 写
提示: 该 docker 组授予 root 用户等效的权限. 有关会如何影响系统安全性的详细信息, 参阅: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
创建 docker 组
groupadd docker
将您的用户添加到 docker 组中
usermod -aG docker $USER
注销并重新登录, 以便重新评估您的组成员资格.
如果在虚拟机上进行测试, 则可能需要重新启动虚拟机才能使更改生效.
在桌面 Linux 环境 (如 X Windows) 上, 完全退出会话并重新登录.
验证您可以不使用运行 docker 命令 sudo
docker run hello-world
五, 镜像加速
建议安装 Docker 之后配置国内镜像加速.
添加内核参数
默认配置下, 如果在 CentOS 使用 Docker CE 看到下面的这些警告信息:
WARING: bridge-nf-call-iptables is disabled
WARING: bridge-nf-call-ip6tables is disabled
请添加内核配置参数以启用这些功能
- net.bridge.bridge-nf-call-ip6tables = 1
- net.bridge.bridge-nf-call-iptables = 1
然后重新加载 sysctl.conf 即可
sysctl -p
来源: https://www.cnblogs.com/hwlong/p/9095852.html