centos 7 docker环境搭建

2019-03-01  本文已影响0人  心思冷清

序言

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


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


安装centos7 最小化安装

安装wget

替换国内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操作界面
上一篇下一篇

猜你喜欢

热点阅读