zoukankan      html  css  js  c++  java
  • Docker CE部署

    一、概述

    Docker 在1.13版本之后,从2017年的3月1日开始,版本命名规则变为如下:

    项目 说明
    版本格式 YY.MM
    Stable  每个季度发行
    Edge版本 每个月发行

    同时Docker划分为CE和EE。CE即社区版(免费,支持后期三个月),EE即企业版,强调安全,付费使用。

    本实验虚拟机CentOS7,采用阿里云yum源安装 

    二、安装Docker CE先决条件

    官方各个版本安装文档: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-datalvm2由需要 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

    五、内核参数修改

    • 添加内核参数

    默认配置下,如果在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

     六、配置加速器

    建议安装Docker之后配置国内镜像加速。

    官方文档:https://docs.docker.com/registry/recipes/mirror/#run-a-registry-as-a-pull-through-cache

    配置Docker守护进程

    --registry-mirrordockerd手动启动时传递选项,或者编辑/etc/docker/daemon.json 和添加registry-mirrors键和值,以使更改持久化。

    {
      "registry-mirrors": ["https://<my-docker-mirror-host>"]
    }

    示例:中国镜像

    中国注册镜像的URL是registry.docker-cn.com通过在docker pull 命令中指定完整路径(包括注册表),您可以像从其他注册表那样从该镜像中提取镜像,例如:

    $ docker pull registry.docker-cn.com/library/ubuntu

    您可以添加"https://registry.docker-cn.com"registry-mirrors阵列中/etc/docker/daemon.json 以默认从China注册表镜像中拉取。

    {
      "registry-mirrors": ["https://registry.docker-cn.com"]
    }

    保存文件并重新加载Docker以使更改生效。

    [root@linux-node1 ~]# systemctl daemon-reload
    [root@linux-node1 ~]# systemctl stop docker
    [root@linux-node1 ~]# systemctl start docker
    [root@linux-node1 ~]# systemctl status docker

    或者,您可以使用--registry-mirror启动参数配置Docker守护程序

    dockerd --registry-mirror=https://registry.docker-cn.com
  • 相关阅读:
    [转]解密回声消除技术之二(应用篇)
    [转]解密回声消除技术之一(理论篇)
    Linux命令练级初级
    [转]win7+ubuntu 13.04双系统安装方法
    c/c++常用代码--清空目录
    c++程序开发利器
    vc2005 编译ACE-6.2.0
    Facebook Login api
    IIS7.0 下使用Intelligencia.UrlRewriter时Session为空问题
    无后缀名伪静态路径在IIS7.0的网站提示 "404
  • 原文地址:https://www.cnblogs.com/hwlong/p/9095852.html
Copyright © 2011-2022 走看看