环境规划:
- docker私有仓库地址:192.168.0.167
- docker客户端地址 : 192.168.0.167
·关闭防火墙和selinux
systemctl stop firewalld.service
systemctl disable firewalld.service
# vi /etc/sysconfig/selinux
SELINUX=disabled
# setenforce 0
服务端
1.安装并启动docker
yum -y install docker
service docker start
chkconfig docker on
2.拉取本地私有仓库registry
[root@localhost ~]# docker pull registry
Trying to pull repository docker.io/registry ...
24dd746e9b9f: Download complete
706766fe1019: Download complete
a62a42e77c9c: Download complete
2c014f14d3d9: Download complete
b7cf8f0d9e82: Download complete
d0b170ebeeab: Download complete
171efc310edf: Download complete
522ed614b07a: Download complete
605ed9113b86: Download complete
22b93b23ebb9: Download complete
2ac557a88fda: Download complete
1f3b4c532640: Download complete
27ebaac643a7: Download complete
ce630195cb45: Download complete
Status: Downloaded newer image for docker.io/registry:latest
3.查看registry镜像
[root@localhost ~]# docker images
docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/ latest ce20c473cd8a 6 days ago 172.3 MB
4.基于私有仓库镜像运行容器
默认情况下,会将仓库存放于容器的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器的/tmp/registry下, 两个目录下都有!
·registry的默认存储路径是/tmp/registry,只是个临时目录,一段时间之后就会消失
·所以使用-v参数,指定个本地持久的路径,
[root@localhost ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry
bb2c0d442df94e281479332c2608ef144f378e71743c5410e36b80c465771a95
root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb2c0d442df9 docker.io/registry:latest "docker-registry" 10 seconds ago Up 7 seconds
5.访问私有仓库
[root@localhost ~]# curl 127.0.0.1:5000/v1/search
{"num_results": 0, "query": "", "results": []} #私有仓库为空,没有提交新镜像到仓库中
6.从Docker HUB 上拉取一个镜像测试
[root@localhost ~]#docker pull busybox
[root@localhost ~]#docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB
7.创建镜像链接为基础镜像打个标签
[root@localhost ~]# docker tag docker.io/busybox 192.168.0.167:5000/busybox
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
192.168.0.167:5000/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB
8.修改docker配置文件,指定私有仓库url
[root@localhost ~]# vim /etc/sysconfig/docker
修改此行
OPTIONS='--insecure-registry 192.168.0.167:5000 '
[root@localhost ~]# service docker restart
9.上传镜像到本地私有仓库
docker push 192.168.0.167:5000/busybox
10.查看私有仓库是否有对应的镜像
[root@localhost ~]# curl 192.168.0.167:5000/v1/search
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/busybox"}]}
11.查看镜像的存储目录和文件
[root@localhost ~]# tree /opt/data/registry/repositories/
/opt/data/registry/repositories/
└── library
└── ssh
├── _index_images
├── json
├── tag_latest
└── taglatest_json
2 directories, 4 files
客户端
1.安装并启动docker
yum -y install docker
service docker start
chkconfig docker on
2.修改docker配置文件,指定私有仓库url
[root@localhost ~]# vim /etc/sysconfig/docker
修改此行
OPTIONS='--insecure-registry 192.168.0.167:5000 '
[root@localhost ~]# service docker restart
3.测试,下载刚才上传的镜像
[root@localhost ~]# docker pull 192.168.0.167:5000/busybox
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
192.168.0.167:5000/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB
docker.io/atcol/docker-registry-ui latest d838355ad903 6 months ago 890.5 MB
更多Docker相关教程见以下内容:
Docker安装应用(CentOS 6.5_x64)
14.04安装Docker
Ubuntu使用VNC运行基于Docker的桌面系统
阿里云CentOS 6.5 模板上安装 Docker
Ubuntu 15.04下安装Docker
在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker
在 Ubuntu 15.04 上如何安装Docker及基本用法
Docker 的详细介绍:
Docker 的下载地址:
本文永久更新链接地址: