美文网首页
centos 7 docker环境搭建

centos 7 docker环境搭建

作者: 心思冷清 | 来源:发表于2019-03-01 12:54 被阅读0次

    序言

    docker是目前轻量级的虚拟化环境,基于docker的环境部署,对于开发和运维有着重要的意义

    • 今后在安装部署应用的时候,在单机或集群上部署的应用环境之间可以相互隔离
    • docker镜像资源非常丰富,今后部署各类中间件,只需要pull一个docker镜像,启动容器即可使用
    • 单机搭建集群环境时,非常节省资源,不想安装虚拟机,占用cpu、内存和磁盘空间巨大,启动很慢
    • portainer镜像提供了可视化操作docker容器的方式,使得应用部署的管理和监控非常方便

    下面按照安装步骤逐一介绍安装过程:


    安装centos7 最小化安装

    • 最小安装centos7 step by step
    • root用户登录
    • ip addr命令查看ip地址
    • putty通过ssh以root账户登录

    安装wget

    • yum -y install wget

      <font color="red">如果该命令有效,则不需安装</font>

    替换国内yum源

    1. 进入/etc/yum.repos.d目录下备份原有文件
    [root@bogon ~]# cd /etc/yum.repos.d/
    
    [root@bogon yum.repos.d]# mkdir repo_bak
    
    [root@bogon yum.repos.d]# mv *.repo repo_bak/
    
    1. 在CentOS中配置使用网易和阿里的开源镜像
    [root@bogon yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
    
    [root@bogon yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
    
    [root@bogon yum.repos.d]# ls
    Centos-7.repo  CentOS-Base-163.repo  repo.bak
    
    1. 清除系统yum缓存并生成新的yum缓存
    [root@bogon yum.repos.d]# ls        # 列出/etc/yum.repos.d/目录下的文件
    Centos-7.repo  CentOS-Base-163.repo  repo.bak
    
    [root@bogon yum.repos.d]# yum clean all     # 清除系统所有的yum缓存
    Loaded plugins: fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    Cleaning repos: base extras updates
    Cleaning up everything
    Cleaning up list of fastest mirrors
    
    [root@bogon yum.repos.d]# yum makecache     # 生成yum缓存
    Loaded plugins: fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    base                                                                                  | 3.6 kB  00:00:00     
    extras                                                                                | 3.4 kB  00:00:00     
    updates                                                                               | 3.4 kB  00:00:00     
    (1/12): base/7/x86_64/filelists_db                                                    | 6.7 MB  00:00:02     
    (2/12): base/7/x86_64/group_gz                                                        | 156 kB  00:00:02     
    (3/12): base/7/x86_64/other_db                                                        | 2.5 MB  00:00:01     
    (4/12): base/7/x86_64/primary_db                                                      | 5.7 MB  00:00:02     
    (5/12): extras/7/x86_64/prestodelta                                                   |  51 kB  00:00:01     
    (6/12): extras/7/x86_64/filelists_db                                                  | 494 kB  00:00:02     
    (7/12): extras/7/x86_64/other_db                                                      |  86 kB  00:00:00     
    (8/12): extras/7/x86_64/primary_db                                                    | 130 kB  00:00:01     
    (9/12): updates/7/x86_64/prestodelta                                                  | 406 kB  00:00:01     
    (10/12): updates/7/x86_64/filelists_db                                                | 2.1 MB  00:00:01     
    (11/12): updates/7/x86_64/other_db                                                    | 354 kB  00:00:00     
    (12/12): updates/7/x86_64/primary_db                                                  | 3.6 MB  00:00:01     
    Determining fastest mirrors
    Metadata Cache Created
    
    1. 安装epel源
    [root@bogon yum.repos.d]# yum list | grep epel-release
    [root@bogon yum.repos.d]# yum install -y epel-release
    [root@bogon yum.repos.d]# ls            # epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件
    Centos-7.repo  CentOS-Base-163.repo  epel.repo  epel-testing.repo  repo.bak
    
    1. 使用阿里开源镜像提供的epel源
    [root@bogon yum.repos.d]# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo    # 下载阿里开源镜像的epel源文件
    [root@localhost yum.repos.d]# ls
    CentOS7-Base-163.repo  epel-7.repo  epel-testing.repo
    Centos-7.repo          epel.repo    repo_bak
    
    1. 再次清除系统yum缓存,并重新生成新的yum缓存
    [root@bogon yum.repos.d]# yum clean all     # 清除系统所有的yum缓存
    [root@bogon yum.repos.d]# yum makecache     # 生成yum缓存
    

    安装Docker-ce

    1. 安装依赖库
    # sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    
    1. 添加稳定版本的 Docker CE yum 源
    # yum-config-manager –add-repo  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    # yum makecache fast
    
    1. 安装 Docker-ce
    # yum -y install docker-ce
    
    # service docker start  #开启Docker服务
    
    # 注意:
    # 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,你可以通过以下方式开启。同理可以开启各种测试版本等。
    # vim /etc/yum.repos.d/docker-ce.repo
    #   将 [docker-ce-test] 下方的 enabled=0 修改为 enabled=1
    #
    # 安装指定版本的Docker-CE:
    # Step 1: 查找Docker-CE的版本:
    # yum list docker-ce.x86_64 --showduplicates | sort -r
    #   Loading mirror speeds from cached hostfile
    #   Loaded plugins: branch, fastestmirror, langpacks
    #   docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
    #   docker-ce.x86_64            17.03.1.ce-1.el7.centos            @docker-ce-stable
    #   docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
    #   Available Packages
    # Step2 : 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.0.ce.1-1.el7.centos)
    # sudo yum -y install docker-ce-[VERSION]
    # yum
    
    1. 配置docker镜像的国内加速器

      写文件daemon.json,内容:

    {
    "registry-mirrors":["https://l10nt4hq.mirror.aliyuncs.com"]
    }
    

    将文件拷贝到/etc/docker目录下

    执行命令:

    # systemctl daemon-reload
    # systemctl restart docker
    

    安装Portainer

    # 下载镜像
    docker pull portainer/portainer
    
    docker run -d -p 9000:9000 --restart=always \
        -v /var/run/docker.sock:/var/run/docker.sock \
        --name prtainer-test \
        portainer/portainer
    
    

    浏览器通过http://容器所在机器IP地址:9000访问即可
    效果如下图:

    portainer操作界面

    相关文章

      网友评论

          本文标题:centos 7 docker环境搭建

          本文链接:https://www.haomeiwen.com/subject/ykpruqtx.html