美文网首页
docker私服搭建

docker私服搭建

作者: 傑仔 | 来源:发表于2018-11-07 16:29 被阅读0次

一、安装docker

###1.安装docker
yum install docker       
###2.启动docker
service docker start     
###3.设置docker自启动
chkconfig docker on     

验证:


图片1.png

二、建镜像仓库

Registry的部署

#运行下面命令获取registry镜像,
$ sudo docker pull registry:2.1.1
#然后启动一个容器,
$ sudo docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:2.1.1

Registry服务默认会将上传的镜像保存在容器的/var/lib/registry,我们将主机的/opt/registry目录挂载到该目录,即可实现将镜像保存到主机的/opt/registry目录了。

运行docker ps看一下容器情况

Notebook-PC ~ $ sudo docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
f3766397a458        registry:2.1.1      "/bin/registry /etc/d"   46 seconds ago      Up 45 seconds       0.0.0.0:5000->5000/tcp   registry

说明我们已经启动了registry服务,打开浏览器输入http://127.0.0.1:5000/v2,出现下面情况说明registry运行正常,

图片2.png

三、验证

现在我们通过将镜像push到registry来验证一下。
我的机器上有个hello-world的镜像,我们要通过docker tag将该镜像标志为要推送到私有仓库,

$ sudo docker tag hello-world 127.0.0.1:5000/hello-world

然后查看以下本地的镜像,

Notebook-PC ~ $ sudo docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry                     2.1.1               b91f745cd233        5 days ago          220.1 MB
ubuntu                       14.04               a5a467fddcb8        6 days ago          187.9 MB
hello-world                  latest              975b84d108f1        2 weeks ago         960 B
127.0.0.1:5000/hello-world   latest              975b84d108f1        2 weeks ago         960 B

接下来,我们运行docker push将hello-world镜像push到我们的私有仓库中,

 $ sudo docker push 127.0.0.1:5000/hello-world
The push refers to a repository [127.0.0.1:5000/hello-world] (len: 1)
975b84d108f1: Image successfully pushed 
3f12c794407e: Image successfully pushed 
latest: digest: sha256:1c7adb1ac65df0bebb40cd4a84533f787148b102684b74cb27a1982967008e4b size: 2744

现在我们可以查看我们本地/opt/registry目录下已经有了刚推送上来的hello-world。我们也在浏览器中输入http://127.0.0.1:5000/v2/_catalog,如下图所示,

图片3.png

现在我们可以先将我们本地的127.0.0.1:5000/hello-world和hello-world先删除掉,

$ sudo docker rmi hello-world

$ sudo docker rmi 127.0.0.1:5000/hello-world

然后使用docker pull从我们的私有仓库中获取hello-world镜像,

Notebook-PC ~   $ sudo docker pull 127.0.0.1:5000/hello-world

Using default tag: latest
latest: Pulling from hello-world
b901d36b6f2f: Pull complete 
0a6ba66e537a: Pull complete 
Digest: sha256:1c7adb1ac65df0bebb40cd4a84533f787148b102684b74cb27a1982967008e4b
Status: Downloaded newer image for 127.0.0.1:5000/hello-world:latest
lienhua34@lienhua34-Compaq-Presario-CQ35-Notebook-PC ~ $ sudo docker images

四、可能问题

1、可能会出现无法push镜像到私有仓库的问题。这是因为我们启动的registry服务不是安全可信赖的。这是我们需要修改docker的配置文件/etc/default/docker,添加下面的内容,

    DOCKER_OPTS="--insecure-registry xxx.xxx.xxx.xxx:5000"

然后重启docker后台进程,

$ sudo service docker restart

2、Get https://10.17.33.70:4400/v1/_ping(https://10.17.33.70:4400/v1/_ping): http: server gave HTTP response to HTTPS client

修改/etc/docker/daemon.json

vi /etc/docker/daemon.json

加入:"insecure-registries":["10.17.33.70:4400"]

{
    "live-restore": true ,
    "insecure-registries":["10.17.33.70:4400"]
}

相关文章

  • Nexus搭建并代理AliYun镜像

    使用 Docker 搭建 Nexus3 私服. Docker 仓库地址 https://hub.docker.co...

  • 2.Docker-registry

    Docker官方提供的Docker Repostory在国内连接不稳定,可以自行搭建私服。 私服可直接使用Dock...

  • 私服搭建及使用

    一、私服环境搭建及配置 1、docker search nexus 2、docker pull sonatype/...

  • 2019-04-30-使用Maven插件向私服发布构建镜像

    如果还没搭建Docker私服请浏览这张卡片 Step1:在客户端添加私服Docker远程访问端口添加变量名DOCK...

  • 2019-04-30-搭建Docker私服

    Step1:拉取并启动registry Step2:验证Docker私服搭建是否成功访问 http://私服IP:...

  • docker - 镜像仓库私服

    docker 安装请参考: docker - 环境搭建类似 maven 私服, 便于管理和共享公司私有的镜像 服务...

  • CICD搭建之 docker私服搭建

    在开发中搭建cicd时docker私服是必不可少的,这里记录一下笔者的私服搭建过程 版本及说明registry是d...

  • docker私服搭建

    一、安装docker 验证: 二、建镜像仓库 Registry的部署 Registry服务默认会将上传的镜像保存在...

  • Docker私服搭建

    配置加速 在https://www.daocloud.io配置加速器 我在CoreOS7系统上使用,上面的命令会修...

  • Docker 私服搭建

    简介 官方的 Docker Hub 是一个用于管理公共镜像的地方,我们可以在上面找到我们想要的镜像,也可以把我们自...

网友评论

      本文标题:docker私服搭建

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