我们在使用Docker时 下载镜像一般都是在外网下载并使用。可是当我们没有外网时我们不得不自己搭建私有仓库。
流程图:
docker 版本
[[email protected] ~]# docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:20:16 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:23:58 2018
OS/Arch: linux/amd64
Experimental: false
安装docker
http://blog.51cto.com/10158955/2125450
下载registry 镜像并且run起来
docker pull registry
[[email protected] ~]# docker pull registry
Using default tag: latest
Trying to pull repository docker.io/library/registry ...
latest: Pulling from docker.io/library/registry
Digest: sha256:672d519d7fd7bbc7a448d17956ebeefe225d5eb27509d8dc5ce67ecb4a0bce54
Status: Downloaded newer image for docker.io/registry:latest
查看下载的镜像
docker images
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.erick.com:5000/hello-world latest b2b03e9146e1 3 weeks ago 33.3MB
registry 2 b2b03e9146e1 3 weeks ago 33.3MB
registry latest b2b03e9146e1 3 weeks ago 33.3MB
通过刚刚下载的镜像Run起来一个容器,并挂载目录
[[email protected] ~]# docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2 ##把宿主机的5000端口映射给docker 的5000端口。
查看此时刚刚创建的容器
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7c92ce5571d5 registry:2 "/entrypoint.sh /etc…" 15 minutes ago Up 15 minutes 0.0.0.0:5000->5000/tcp relaxed_saha
进入容器我们查看容器的目录
[[email protected] ~]# sudo docker exec -it 7c92ce5571d5 sh
/ #
exit 退出容器
然后在”/etc/docker/“目录下,创建”daemon.json“文件。并添加
[[email protected] ~]# cat /etc/docker/daemon.json
{
"insecure-registries": [
"docker.erick.com:5000"
]
}
修改/etc/hosts 能够 解析到 docker.erick.com
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.254.137 docker.erick.com
注意:每个版本的docker修改配置内容都不同
[[email protected] ~]# cat /etc/sysconfig/docker
OPTIONS=‘--selinux-enabled --insecure-registry 192.168.254.137:5000‘
重新启动docker 服务
systemctl restart docker
开始把镜像导入到私有仓库
查看此时存在的docker 镜像
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.erick.com:5000/hello-world latest b2b03e9146e1 3 weeks ago 33.3MB
registry 2 b2b03e9146e1 3 weeks ago 33.3MB
registry latest b2b03e9146e1 3 weeks ago 33.3MB
注意:为docker.io/hello-world 镜像更名为docker.erick.com:5000/hello-world
把刚刚更改好名字的镜像上传至私有镜像
可以看到我们已经把镜像上传到了 我们自己搭建的私有镜像仓库。我们看下存放仓库的位置
先查看宿主机:
原文地址:http://blog.51cto.com/10158955/2152305