经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Docker » 查看文章
CentOS下安装Docker CE教程
来源:cnblogs  作者:请叫我大树  时间:2019/7/8 8:36:22  对本文有异议

一、安装前准备

1、硬件要求

CentOS 7(64-bit),内核版本不能低于3.10;

CentOS 6.5(64-bit或更新的版本),内核版本为 2.6.32-431 或者更高版本,一般不建议在CentOS 6.x下安装Docker,因为往往CentOS 6.x往往需要先升级内核版本以达到安装条件,但是升级内核可能会导致开不了机之类的问题。

2、卸载旧版本

较旧版本的Docker被称为dockerdocker-engine。如果已安装这些,请卸载它们以及相关的依赖项。

  1. $ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

 

二、安装Docker

1、使用yum安装

①.安装所需依赖包

  1. 1 sudo yum install -y yum-utils device-mapper-persistent-data lvm2

鉴于国内网络问题,强烈建议使用国内源!!!

国内源:

  1. 1 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

官方源:

  1. 1 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

如果需要测试版本的 Docker CE 请使用以下命令:

  1. 1 sudo yum-config-manager --enable docker-ce-test

如果需要每日构建版本的 Docker CE 请使用以下命令:

  1. 1 sudo yum-config-manager --enable docker-ce-nightly

②.更新yum缓存并安装Docker-ce

  1. 1 sudo yum makecache fast
  2. 2 sudo yum -y install docker-ce

③.启动Docker-ce

  1. 1 sudo systemctl enable docker
  2. 2 sudo systemctl start docker

④.建立docker用户组

默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。

建立docker组:

  1. 1 sudo groupadd docker

将当前用户添加到docker组中:

  1. 1 sudo usermod -aG docker $USER

退出当前终端并重新登录,进行如下命令测试,若能正常输出以上信息,则说明安装成功。

  1. [root@localhost ~]# docker run hello-world
  2. Hello from Docker!
  3. This message shows that your installation appears to be working correctly.
  4. To generate this message, Docker took the following steps:
  5. 1. The Docker client contacted the Docker daemon.
  6. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  7. (amd64)
  8. 3. The Docker daemon created a new container from that image which runs the
  9. executable that produces the output you are currently reading.
  10. 4. The Docker daemon streamed that output to the Docker client, which sent it
  11. to your terminal.
  12. To try something more ambitious, you can run an Ubuntu container with:
  13. $ docker run -it ubuntu bash
  14. Share images, automate workflows, and more with a free Docker ID:
  15. https://hub.docker.com/
  16. For more examples and ideas, visit:
  17. https://docs.docker.com/get-started/

⑤.镜像加速

如果在使用过程中发现国内网络拉取 Docker 镜像十分缓慢,比如出现拉取镜像Timeout的问题,可以配置 Docker 国内镜像加速

例如,对于使用 systemd 的系统,请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)

  1. {
  2. "registry-mirrors": [
  3. "https://dockerhub.azk8s.cn",
  4. "https://reg-mirror.qiniu.com"
  5. ]
  6. }
  7. #注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。

重启docker服务:

  1. 1 sudo systemctl daemon-reload
  2. 2 sudo systemctl restart docker

查看加速器是否生效:

执行 docker info,如果从结果中看到了如下内容,说明配置成功。

  1. Registry Mirrors:
  2. https://dockerhub.azk8s.cn/
  3. https://reg-mirror.qiniu.com/

2、使用脚本自动安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS 系统上可以使用这套脚本安装:

  1. 1 curl -fsSL get.docker.com -o get-docker.sh
  2. 2 sudo sh get-docker.sh --mirror Aliyun

执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker CE 的 edge 版本安装在系统中。

3、添加内核参数

如果在 CentOS 使用 Docker CE 看到下面的这些警告信息:

  1. WARNING: bridge-nf-call-iptables is disabled
  2. WARNING: bridge-nf-call-ip6tables is disabled

请添加内核配置参数以启用这些功能。

  1. 1 sudo tee -a /etc/sysctl.conf <<-EOF
  2. 2 net.bridge.bridge-nf-call-ip6tables = 1
  3. 3 net.bridge.bridge-nf-call-iptables = 1
  4. 4 EOF

然后重新加载 sysctl.conf 即可

  1. 1 sudo sysctl -p

4、参考文档:

 

2019-07-07 17:28:49

原文链接:http://www.cnblogs.com/lxh9632/p/11146863.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号