共计 7229 个字符,预计需要花费 19 分钟才能阅读完成。
解决 http 协议的问题:
方法一:解决 HTTPS 问题
安装 nginx,配置 HTTPS 协议
方法二:修改 docker 的配置文件
vim /etc/default/docker 增加
OPTIONS=”–insecure-registry 192.168.10.249:5000″
准备配置环境:
主机名 | 主机 IP | 服务 |
docker-images | 10.0.0.5 | docker 私有库库配置 |
10.0.0.6 | docker 客户端 |
[root@docker-images ~]# cat /etc/RedHat-release
CentOS Linux release 7.2.1511 (Core)
[root@docker-images ~]# uname -r
3.10.0-327.el7.x86_64
[root@docker-images ~]# uname -m
x86_64
[root@docker-images ~]# uname -a
Linux docker-images 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@docker-images ~]#
开始配置(镜像库)
1、关闭防火墙和 selinux
[root@docker-images ~]# systemctl stop firewalld
[root@docker-images ~]# systemctl disable firewalld #永久
[root@docker-images ~]# setenforce 0
[root@docker-images ~]# getenforce
Permissive
[root@docker-images ~]#
2、安装 docker
yum install docker
[root@docker-images ~]# systemctl enable docker #加入开机自启动
[root@docker-images ~]# systemctl start docker #开启服务
3、下载本地私有库 registry
[root@docker-images ~]# docker pull registry #默认下载最新版
[root@docker-images ~]# docker images #查看下载的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
[root@docker-images ~]#
4、基于私有仓库镜像运行容器
[root@docker-images ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry
# 默认仓库创建在 /tmp/registry,用 - v 参数指定仓库存放位置
1e8b1a03013ee66034b40aee1820000a2ccf026a3b1e43606f3e4007b2a9d455
[root@docker-images ~]#
[root@docker-images ~]# docker ps #查看运行容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e8b1a03013e docker.io/registry “/entrypoint.sh /etc/” 35 seconds ago Up 32 seconds 0.0.0.0:5000->5000/tcp goofy_mcnulty
[root@docker-images ~]#
5、访问私有仓库
[root@docker-images ~]# curl 127.0.0.1:5000/v2
<a href=”https://www.linuxidc.com/v2/”>Moved Permanently</a>.
[root@docker-images ~]#
# 说明 registry 部署成功
6、为基础镜像打标签
[root@docker-images ~]# docker search docker.io/Fedora/ssh|grep docker.io/fedora/ssh
docker.io docker.io/fedora/ssh 20 [OK]
[root@docker-images ~]# docker pull docker.io/fedora/ssh #下载镜像
[root@docker-images ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
[root@docker-images ~]# docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh #打标签
[root@docker-images ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
127.0.0.1:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
[root@docker-images ~]#
[root@docker-images ~]# vim /etc/sysconfig/docker
OPTIONS=”–selinux-enabled –insecure-registry 10.0.0.5:5000″ #定制私有仓库 URL
[root@docker-images ~]# systemctl restart docker
7、提交镜像到本地私有库
[root@docker-images ~]# docker start 1e8 #开启本地库
1e8
[root@docker-images ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e8b1a03013e docker.io/registry “/entrypoint.sh /etc/” 4 hours ago Up 3 seconds 0.0.0.0:5000->5000/tcp goofy_mcnulty
[root@docker-images ~]#
[root@docker-images ~]# docker push 127.0.0.1:5000/ssh #上传打好标签的库
The push refers to a repository [127.0.0.1:5000/ssh]
482d621bda33: Pushed
510f15c27a8b: Pushed
e4f86288aaf7: Pushed
latest: digest: sha256:5ad5aec14bb7aa63fdcea1772db6ab5b5de99b0a023d234e61f5aa8c9435e8ff size: 948
[root@docker-images ~]#
8、查看已经上传好的镜像
[root@docker-images ~]# curl 10.0.0.5:5000/v2/_catalog
{“repositories”:[“ssh”]}
[root@docker-images ~]#
浏览器中查看已经上传的镜像
http://10.0.0.5:5000/v2/_catalog
9、测试库是否可用,在准备好环境的另一台测试机上面下载上传的镜像
[root@centos7 ~]# vim /etc/sysconfig/docker #加入私有仓库地址
OPTIONS=”–selinux-enabled –insecure-registry 10.0.0.5:5000″
[root@centos7 ~]# systemctl restart docker
[root@centos7 ~]# docker pull 10.0.0.5:5000/ssh
可以看到已经可以下载镜像,证明私有仓库创建成功
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.0.0.5:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
[root@centos7 ~]#
接下来通过自己的私有库运行一个 centos7 容器
1、从其他的数据库上 save 一个 centos 镜像推送到私有库服务器上
[root@docker-images ~]# ls
anaconda-ks.cfg centos.tar
[root@docker-images ~]# docker load < centos.tar #将镜像导入 docker
34e7b85d83e4: Loading layer [==================================================>] 199.9 MB/199.9 MB
Loaded image: docker.io/centos:latest ] 557.1 kB/199.9 MB
[root@docker-images ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
127.0.0.1:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/centos latest 67591570dd29 12 weeks ago 191.8 MB
[root@docker-images ~]#
2、再次打上自己的标签
[root@docker-images ~]# docker tag docker.io/centos:latest 10.0.0.5:5000/lcentos
#为了区别前面的,我将 centos 做了其他标记
[root@docker-images ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 047218491f8c 10 days ago 33.17 MB
127.0.0.1:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/fedora/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
docker.io/centos latest 67591570dd29 12 weeks ago 191.8 MB
10.0.0.5:5000/lcentos latest 67591570dd29 12 weeks ago 191.8 MB
[root@docker-images ~]#
3、上传标记好的镜像到自己的私有库
[root@docker-images ~]# docker push 10.0.0.5:5000/lcentos
4、查看上传好的镜像
[root@docker-images ~]# curl http://10.0.0.5:5000/v2/_catalog
{“repositories”:[“lcentos”,”ssh”]}
[root@docker-images ~]#
浏览器查看
5、再次到准备好环境的那台测试机上面 pull
[root@centos7 ~]# docker pull 10.0.0.5:5000/lcentos
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.0.0.5:5000/ssh latest ad6a3ff29626 4 weeks ago 396.7 MB
10.0.0.5:5000/lcentos latest 67591570dd29 12 weeks ago 191.8 MB
[root@centos7 ~]#
6、创建并运行一个容器
[root@centos7 ~]# docker run -d -it –privileged=false -p 80:80 –name abccentos 10.0.0.5:5000/lcentos /bin/bash
15b9f42b3d63846085664139bff0c041f614bc2b717787686d23785d98b37160
[root@centos7 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15b9f42b3d63 10.0.0.5:5000/lcentos “/bin/bash” 16 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp abccentos
[root@centos7 ~]#
7、进入容器查看,可以看到 centos 的版本等信息
[root@centos7 ~]# docker attach 15b9f42b3d63
[root@15b9f42b3d63 /]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@15b9f42b3d63 /]# uname -r
3.10.0-327.el7.x86_64
[root@15b9f42b3d63 /]# uname -a
Linux 15b9f42b3d63 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@15b9f42b3d63 /]#
以上就是整个创建私有镜像库的过程,欢迎一起交流学习。
更多 Docker 相关教程见以下内容:
Docker 安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm
Ubuntu 14.04 安装 Docker http://www.linuxidc.com/linux/2014-08/105656.htm
Ubuntu 使用 VNC 运行基于 Docker 的桌面系统 http://www.linuxidc.com/Linux/2015-08/121170.htm
阿里云 CentOS 6.5 模板上安装 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm
Ubuntu 15.04 下安装 Docker http://www.linuxidc.com/Linux/2015-07/120444.htm
在 Ubuntu Trusty 14.04 (LTS) (64-bit)安装 Docker http://www.linuxidc.com/Linux/2014-10/108184.htm
在 Ubuntu 15.04 上如何安装 Docker 及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm
Ubuntu 16.04 上 Docker 使用手记 http://www.linuxidc.com/Linux/2016-12/138490.htm
Docker 的详细介绍:请点这里
Docker 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141850.htm