美文网首页
微服务框架搭建系列: 3.搭建Docker Registry私服

微服务框架搭建系列: 3.搭建Docker Registry私服

作者: creolophuth | 来源:发表于2019-02-01 19:02 被阅读0次

搭建Docker Registry私服

重复一次之前的动作,搞一个服务器,在Docker Hub https://hub.docker.com 上搜 Registry ,第一个也是标星最多的那个就是了。拖进Docker docker pull registry。然后新建/usr/local/docker/registry/docker-compose.yml ,写入:

version: '3.1'
services:
  registry:
    image: registry
    restart: always
    container_name: registry
    ports:
      - 5000:5000
    volumes:
      - /usr/local/docker/registry/data:/var/lib/registry

然后dicker-compose up ,为喜欢看一眼后台跑起来的样子,就不-d了。
后台跑起来之后,浏览器试一下 http://192.168.111.133:5000/v2/ ,这是出现了

1.png
说明Registry私服就搭建好了,因为还没有往上推镜像,所以里面没有内容。
搭建好之后,还需要配置一下,目的是再往docker里拖镜像的时候先从自己搭建的Registry私服里找。找到之前配置docker国内加速的/etc/docker/daemon.json文件,修改为如下:
{
  "registry-mirrors": [
    "https://registry.docker-cn.com"
  ],
  "insecure-registries": [
    "192.168.111.133:5000"
  ]
}

然后重启服务,

sudo systemctl daemon-reload
sudo systemctl restart docker

重启后看一看配置成功里没有,输入docker info,有这一项,说明行了。

2.png
至此,Registry私服就搭建好也能用了,如果有需要,还可以再部署docker-registry-frontend docker-registry-web等浏览器图像界面。

************************************昏割一下****

现在开始试一试,往私服里推拖镜像。
先往docker里拖一个hello-world镜像docker pull hello-world
docker images看到hello-world已经有了。

3.png

然后要用到命令 “docker tag : 标记本地镜像,将其归入某一仓库” ,语法规则为
docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
IMAGE[:TAG] 就是 hello-world:latest ,
[REGISTRYHOST/]就是 192.168.111.133:5000/ ,
[USERNAME/]就是 creolophuth/ ,
NAME别变了,还是 hello-world ,
[:TAG]版本号,指定为 :1.0.0 ,
完整的命令就是

docker tag hello-world:latest 192.168.111.133:5000/creolophuth/hello-world:1.0.0 

标记好之后,docker images一下,看到镜像已经有了,然后推到Registry私服上:

docker push 192.168.111.133:5000/creolophuth/hello-world

显示已推


4.png

查看全部镜像

curl -XGET http://192.168.111.133:5000/v2/_catalog

如果库里镜像太多,可以查看指定镜像

curl -XGET http://192.168.111.133:5000/v2/creolophuth/hello-world/tags/list

两个命令都试一下,都能找到,说明镜像已经推到私服库里了


5.png

现在已经推上去了,接下来试试往docker里拖,拖之前先把docker里的镜像先删掉

docker rmi hello-world
docker rmi 192.168.111.133:5000/creolophuth/hello-world

输第二条命令后报错了Error: No such image: 192.168.111.133:5000/creolophuth/hello-world ,可能因为两个镜像hello-world和192.168.111.133:5000/creolophuth/hello-world的id是一样的,但是docker images后192.168.111.133:5000/creolophuth/hello-world还在那没有变成虚悬镜像。
那么直接用id删除试试

docker rmi fce289e99eb9

控制台显示成功了,docker images后也干净了。
现在从私服库往docker拖hello-world镜像

docker pull 192.168.111.133:5000/creolophuth/hello-world:1.0.0

显示成功 Pull completedocker images后发现镜像已经进去了,需要注意的是,如果不输入版本号,docker默认会去找latest版本,而我没有把1.0.0指定为latest,库里也没有latest,会导致拖镜像失败。

至此,开发前的准备工作就算做完了有了Gitlab、Nexus、Registry的私服,在不连外网的条件下也能完成开发了(但是库里得有东西)。

相关文章

网友评论

      本文标题:微服务框架搭建系列: 3.搭建Docker Registry私服

      本文链接:https://www.haomeiwen.com/subject/feydsqtx.html