CentOS 7下搭建和使用Docker私有仓库

下载registry镜像

docker pull registry

防火墙添加运行5000端口

firewall-cmd –zone=public –add-port=5000/tcp –permanent
firewall-cmd –reload

通过镜像启动一个容器

docker run -d -v /home/nin/registry:/var/lib/registry -p 5000:5000 –restart=always –privileged=true –name registry registry:latest

参数说明:
-v /home/nin/registry:/var/lib/registry :默认情况下,会将仓库存放于容器内的/var/lib/registry目录下,指定本地目录挂载到容器
–privileged=true :CentOS7中的安全模块selinux把权限禁掉了,参数给容器加特权,不加上传镜像会报权限错误(OSError: [Errno 13] Permission denied: ‘/var/lib/registry/repositories/library’)或者(Received unexpected HTTP status: 500 Internal Server Error)错误

客户端上传镜像

修改/etc/sysconfig/docker(Ubuntu下配置文件地址为:/etc/init/docker.conf),增加启动选项(已有参数的在后面追加),之后重启docker,不添加报错,https证书问题。

OPTIONS=’–insecure-registry 192.168.0.163:5000′ #CentOS 7系统

因为Docker从1.3.X之后,与docker registry交互默认使用的是https,而此处搭建的私有仓库只提供http服务在docker公共仓库下载一个镜像

docker pull docker.io/centos

来修改一下该镜像的tag
docker tag centos 192.168.0.163:5000/centos

把打了tag的镜像上传到私有仓库
docker push 192.168.0.163:5000/centos

客户端添加私有仓库地址

# 添加这一行
ADD_REGISTRY=’–add-registry 192.168.0.163:5000′

加上后,search镜像,私有仓库和docker hub上都会显示;不加搜索私有仓库,需要命令中指定私有仓库ip

使用仓库中的镜像

查询私有仓库中的所有镜像,使用docker search命令:
curl -u myuser https://registry_ip:5000/v1/search
curl registry_ip:5000/v1/search

docker search registry_ip:5000/ #centos 7
docker search registry_ip:5000/library #centos 6

查询仓库中指定账户下的镜像,则使用如下命令:
docker search registry_ip:5000/account/

使用中遇到的问题

Get https://192.168.0.163:5000/v1/_ping: Tunnel Connection Failed

解决方案:
修改daemon.json文件vim /etc/docker/daemon.json
添加:{ “insecure-registries”:[“192.168.0.163:5000”]}

 

 

CentOS7安装Docker CE

系统要求

Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10。 CentOS 7 满足最低内核的要求,但由于内核版本比较低,部分功能(如 overlay2 存储层驱动)无法使用,并且部分功能可能不太稳定。

卸载旧版本

旧版本的 Docker 称为 docker 或者 docker-engine,使用以下命令卸载旧版本:

$ yum remove docker docker-common docker-selinux docker-engine

使用yum源安装

执行以下命令安装依赖包:yum install -y yum-utils device-mapper-persistent-data lvm2

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

国内源

执行下面的命令添加 yum 软件源:
$ yum-config-manager –add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

以上命令会添加稳定版本的 Docker CE yum 源。从 Docker 17.06 开始,edge test 版本的 yum 源也会包含稳定版本的 Docker CE。

官方源

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

如果需要最新版本的 Docker CE, 请使用以下命令:
$ sudo yum-config-manager –enable docker-ce-edge
$ sudo yum-config-manager –enable docker-ce-test

安装 Docker CE

更新 yum 软件源缓存,并安装 docker-ce。
$ sudo yum makecache fast
$ sudo yum install docker-ce

脚本自动安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS 系统上可以使用这套脚本安装:
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh –mirror Aliyun

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

启动 Docker CE

$ systemctl enable docker
$ systemctl start docker

建立 docker 用户组

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

建立 docker 组:
$ groupadd docker

将当前用户加入 docker 组:
$ usermod -aG docker $USER

$USER是需要加入的用户,例如zhangsan

镜像加速

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,强烈建议安装 Docker 之后配置 国内镜像加速。

一般到DaoCloud注册一个帐号,注册完毕后会返回一个命令行。

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://XXXXXX.m.daocloud.io

该脚本可以将 –registry-mirror 加入到你的 Docker 配置文件 /etc/docker/daemon.json 中。适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1,其他版本可能有细微不同。更多详情请访问文档。

这样拉取就会感觉到一个快,不然那网速就是老牛。

添加内核参数

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

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

请添加内核配置参数以启用这些功能。
$ sudo tee -a /etc/sysctl.conf <<-EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

然后重新加载 sysctl.conf 即可
$ sysctl -p

 

 

CentOS7下安装Docker-Compose

在使用Docker时,需要整体启动应用,一般会用到 docker-compose工具,如果是新安装的CentOS7是不会被安装的,但是安装这个工具的前提是要安装pip工具。

  • 首先检查CentOS7有没有安装python-pip包,直接执行yum install python-pip

[root@ds-163 ~]# yum install python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No package python-pip available.
Error: Nothing to do

  • 没有python-pip包就执行命令 yum -y install epel-release

[root@ds-163 ~]# yum install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
–> Running transaction check
—> Package epel-release.noarch 0:7-9 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
epel-release noarch 7-9 extras 14 k

Transaction Summary
===============================================================================================================================
Install 1 Package

Total download size: 14 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-9.noarch.rpm | 14 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-9.noarch 1/1
Verifying : epel-release-7-9.noarch 1/1

Installed:
epel-release.noarch 0:7-9

Complete!

  • 执行成功之后,再次执行yum install python-pip

[root@ds-163 ~]# yum install python-pip
Loaded plugins: fastestmirror
epel/x86_64/metalink | 7.4 kB 00:00:00
epel | 4.7 kB 00:00:00
epel/x86_64/updateinfo FAILED
https://mirror.lzu.edu.cn/epel/7/x86_64/repodata/c933270bd133c8494e8684f1dc3a3829f939a62be7148a0f8640c691b61301c3-updateinfo.xml.bz2: [Errno 14] HTTPS Error 404 – Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article

https://access.redhat.com/articles/1320623

If above article doesn’t help to resolve this issue please create a bug on https://bugs.centos.org/

epel/x86_64/updateinfo FAILED ] 0.0 B/s | 0 B –:–:– ETA
http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/repodata/c933270bd133c8494e8684f1dc3a3829f939a62be7148a0f8640c691b61301c3-updateinfo.xml.bz2: [Errno 14] HTTP Error 404 – Not Found
Trying other mirror.
(1/3): epel/x86_64/group_gz | 266 kB 00:00:00
epel/x86_64/updateinfo FAILED
http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/7/x86_64/repodata/c933270bd133c8494e8684f1dc3a3829f939a62be7148a0f8640c691b61301c3-updateinfo.xml.bz2: [Errno 14] HTTP Error 404 – Not Found
Trying other mirror.
(2/3): epel/x86_64/updateinfo | 879 kB 00:00:00
(3/3): epel/x86_64/primary_db | 6.2 MB 00:02:59
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirror.lzu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
–> Running transaction check
—> Package python2-pip.noarch 0:8.1.2-5.el7 will be installed
–> Processing Dependency: python-setuptools for package: python2-pip-8.1.2-5.el7.noarch
–> Running transaction check
—> Package python-setuptools.noarch 0:0.9.8-7.el7 will be installed
–> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-7.el7.noarch
–> Running transaction check
—> Package python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7 will be installed
–> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch
–> Running transaction check
—> Package python-backports.x86_64 0:1.0-8.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
python2-pip noarch 8.1.2-5.el7 epel 1.7 M
Installing for dependencies:
python-backports x86_64 1.0-8.el7 base 5.8 k
python-backports-ssl_match_hostname noarch 3.4.0.2-4.el7 base 12 k
python-setuptools noarch 0.9.8-7.el7 base 397 k

Transaction Summary
===============================================================================================================================
Install 1 Package (+3 Dependent packages)

Total download size: 2.1 M
Installed size: 9.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): python-backports-1.0-8.el7.x86_64.rpm | 5.8 kB 00:00:00
(2/4): python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch.rpm | 12 kB 00:00:00
(3/4): python-setuptools-0.9.8-7.el7.noarch.rpm | 397 kB 00:00:00
warning: /var/cache/yum/x86_64/7/epel/packages/python2-pip-8.1.2-5.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for python2-pip-8.1.2-5.el7.noarch.rpm is not installed
(4/4): python2-pip-8.1.2-5.el7.noarch.rpm | 1.7 MB 00:00:01
——————————————————————————————————————————-
Total 1.0 MB/s | 2.1 MB 00:00:02
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
Userid : “Fedora EPEL (7) <epel@fedoraproject.org>”
Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
Package : epel-release-7-9.noarch (@extras)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python-backports-1.0-8.el7.x86_64 1/4
Installing : python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch 2/4
Installing : python-setuptools-0.9.8-7.el7.noarch 3/4
Installing : python2-pip-8.1.2-5.el7.noarch 4/4
Verifying : python2-pip-8.1.2-5.el7.noarch 1/4
Verifying : python-setuptools-0.9.8-7.el7.noarch 2/4
Verifying : python-backports-1.0-8.el7.x86_64 3/4
Verifying : python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch 4/4

Installed:
python2-pip.noarch 0:8.1.2-5.el7

Dependency Installed:
python-backports.x86_64 0:1.0-8.el7 python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7
python-setuptools.noarch 0:0.9.8-7.el7

Complete!

  • 对安装好的pip进行升级 pip install –upgrade pip

[root@ds-163 ~]# pip install –upgrade pip
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
91% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枎 | 1.1MB 935kB/s eta 0:00:0 92% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枌 | 1.2MB 942kB/s eta 0:00:0 93% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枈 | 1.2MB 863kB/s eta 0:00:0 93% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅 | 1.2MB 770kB/s eta 0:00:0 94% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 1.2MB 801kB/s eta 0:00:0 95% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 1.2MB 896kB/s eta 0:00:0 96% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 1.2MB 897kB/s eta 0:00:0 97% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 1.2MB 859kB/s eta 0:00:0 97% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枍| 1.2MB 781kB/s eta 0: 98% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枊| 1.2MB 1.2MB/s eta 0: 99% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枆| 1.2MB 1.3MB/s eta 0: 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1.3MB 526kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Successfully installed pip-9.0.1

pip工具就安装完成。

  • 安装docker-compose,终端直接输入 pip install docker-compose

[root@ds-163 ~]# pip install docker-compose
Collecting docker-compose
Downloading docker_compose-1.18.0-py2.py3-none-any.whl (111kB)
91% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枎 | 102kB 355kB/s eta 0:00:0 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 112kB 359kB/s
Collecting websocket-client<1.0,>=0.32.0 (from docker-compose)
Downloading websocket_client-0.46.0-py2.py3-none-any.whl (200kB)
91% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枍 | 184kB 1.2MB/s eta 0:00:0 97% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 194kB 1.2MB/s eta 0:00:0 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 204kB 810kB/s
Collecting docker<3.0,>=2.6.1 (from docker-compose)
Downloading docker-2.7.0-py2.py3-none-any.whl (119kB)
94% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 112kB 391kB/s eta 0:00:0 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 122kB 372kB/s
Collecting backports.ssl-match-hostname>=3.5; python_version < “3.5” (from docker-compose)
Downloading backports.ssl_match_hostname-3.5.0.1.tar.gz
Collecting PyYAML<4,>=3.10 (from docker-compose)
Downloading PyYAML-3.12.tar.gz (253kB)
93% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枆 | 235kB 624kB/s eta 0:00:0 97% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 245kB 566kB/s eta 0:00:0 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 256kB 527kB/s
Collecting dockerpty<0.5,>=0.4.1 (from docker-compose)
Downloading dockerpty-0.4.1.tar.gz
Collecting ipaddress>=1.0.16; python_version < “3.3” (from docker-compose)
Downloading ipaddress-1.0.19.tar.gz
Collecting docopt<0.7,>=0.6.1 (from docker-compose)
Downloading docopt-0.6.2.tar.gz
Collecting enum34<2,>=1.0.4; python_version < “3.4” (from docker-compose)
Downloading enum34-1.1.6-py2-none-any.whl
Collecting requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1 (from docker-compose)
Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 92kB 87kB/s
Collecting texttable<0.10,>=0.9.0 (from docker-compose)
Downloading texttable-0.9.1.tar.gz
Collecting cached-property<2,>=1.2.0 (from docker-compose)
Downloading cached_property-1.3.1-py2.py3-none-any.whl
Collecting jsonschema<3,>=2.5.1 (from docker-compose)
Downloading jsonschema-2.6.0-py2.py3-none-any.whl
Collecting six<2,>=1.3.0 (from docker-compose)
Downloading six-1.11.0-py2.py3-none-any.whl
Collecting docker-pycreds>=0.2.1 (from docker<3.0,>=2.6.1->docker-compose)
Downloading docker_pycreds-0.2.1-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading certifi-2018.1.18-py2.py3-none-any.whl (151kB)
94% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻| 143kB 181kB/s eta 0:00:0 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 153kB 174kB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
92% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枌 | 122kB 154kB/s eta 0:00:0 99% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 133kB 167kB/s eta 0: 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 143kB 187kB/s
Collecting idna<2.7,>=2.5 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading idna-2.6-py2.py3-none-any.whl (56kB)
100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 61kB 160kB/s
Collecting urllib3<1.23,>=1.21.1 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
92% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枈 | 122kB 157kB/s eta 0:00:0 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 133kB 146kB/s
Collecting functools32; python_version == “2.7” (from jsonschema<3,>=2.5.1->docker-compose)
Downloading functools32-3.2.3-2.zip
Installing collected packages: six, websocket-client, backports.ssl-match-hostname, docker-pycreds, certifi, chardet, idna, urllib3, requests, ipaddress, docker, PyYAML, dockerpty, docopt, enum34, texttable, cached-property, functools32, jsonschema, docker-compose
Found existing installation: backports.ssl-match-hostname 3.4.0.2
Uninstalling backports.ssl-match-hostname-3.4.0.2:
Successfully uninstalled backports.ssl-match-hostname-3.4.0.2
Running setup.py install for backports.ssl-match-hostname … done
Found existing installation: chardet 2.2.1
Uninstalling chardet-2.2.1:
Successfully uninstalled chardet-2.2.1
Running setup.py install for ipaddress … done
Running setup.py install for PyYAML … done
Running setup.py install for dockerpty … done
Running setup.py install for docopt … done
Running setup.py install for texttable … done
Running setup.py install for functools32 … done
Successfully installed PyYAML-3.12 backports.ssl-match-hostname-3.5.0.1 cached-property-1.3.1 certifi-2018.1.18 chardet-3.0.4 docker-2.7.0 docker-compose-1.18.0 docker-pycreds-0.2.1 dockerpty-0.4.1 docopt-0.6.2 enum34-1.1.6 functools32-3.2.3.post2 idna-2.6 ipaddress-1.0.19 jsonschema-2.6.0 requests-2.18.4 six-1.11.0 texttable-0.9.1 urllib3-1.22 websocket-client-0.46.0

注意:执行docker-compse可能会出现错误,需要在更新命令行,在终端直接输入 pip install –upgrade backports.ssl_match_hostname

  • 确认版本

[root@ds-163 ~]# docker-compose -version
docker-compose version 1.18.0, build 8dd22a9

 

CentOS7中配置Docker的yum源并安装

Docker现在用的越来越多,现在抽出点时间来写个博客,作为自己学习的一个纪录。

  • wget安装
    用Centos的Mini版一般不包含wget,首先要安装wget。

yum install wget

yum install net-tools

yum install lsof

  • 备份CentOS-Base.repo,取得aliyun源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

  • 下载

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@ds-163 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2573 100 2573 0 0 20177 0 –:–:– –:–:– –:–:– 20420
[root@ds-163 ~]# cd /etc/yum.repos.d/
[root@ds-163 yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
CentOS-Base.repo.backup CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo

  • 运行yum makecache生成缓存

配置好yum源之后,可以通过yum的list命令,获取可以安装的docker版本

yum list docker –showduplicates | sort -r
yum list docker-engine.x86_64 –showduplicates | sort -r

可以看出,阿里云镜像源中的docker安装包与docker官方提供的安装包名称并不相同,所以在使用yum安装的时候,很可能安装的是阿里云的docker,虽然配置了docker官方的源,却无法安装最新的docker版本。这里需要注意的是,如果想要使用docker官方的源中的安装包升级docker,那么要提供安装包的名字为docker-engine,这样就可以找到各个版本的docker了。

  • 删除docker

如果之前安装了docker,一定要将旧版本删除。

yum -y remove docker docker-common container-selinux
yum -y remove docker-selinux

  • 安装yum管理工具

yum install -y yum-utils

  • 加入官方docker源

yum-config-manager \
–add-repo \
https://docs.docker.com/v1.13/engine/installation/linux/repo_files/centos/docker.repo

  • docker测试版本

可以打开和关闭测试版本使用

yum-config-manager –enable docker-testing

yum-config-manager –disable docker-testing

  • 构建缓存

yum makecache fast

  • 安装docker

yum -y install docker-engine-1.13.1

官方下载太慢,下载的时候要有个心理准备。这个不推荐使用,添加其他源进行下载安装。

添加软件源信息
yum-config-manager –add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce

  • 启动docker

systemctl start docker

systemctl enable docker

  • 测试docker

可以通过命令查看当前docker版本
docker version

docker run hello-world

  • 删除docker

yum -y remove docker-engine
rm -rf /var/lib/docker