龙空技术网

Debain或ubuntu下搭建docker私有镜像仓库

大智家plus 68

前言:

今天咱们对“ubuntu devsda”大体比较珍视,同学们都需要了解一些“ubuntu devsda”的相关内容。那么小编同时在网上汇集了一些关于“ubuntu devsda””的相关知识,希望兄弟们能喜欢,朋友们一起来学习一下吧!

1 安装docker环境

为了能快速拉取镜像,建议配置一下docker的国内镜像加速地址,网上这类教程很多,docker安装此处不再赘述,也可参考《Debian及ubuntu下如何搭建docker运行环境》

2 拉取registry镜像

root@debian:~# docker pull registry

Using default tag: latest

latest: Pulling from library/registry

79e9f2f55bf5: Pull complete

0d96da54f60b: Pull complete

5b27040df4a2: Pull complete

e2ead8259a04: Pull complete

3790aef225b9: Pull complete

Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375

Status: Downloaded newer image for registry:latest

docker.io/library/registry:latest

root@debian:~# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

registry latest b8604a3fe854 12 months ago 26.2MB

3 在宿主机上创建数据存储目录

root@debian:/# mkdir -p /opt/registryData

4 启动registry容器

容器配置为后台运行,将容器服务端口映射到宿主机80端口,挂载数据存储目录,设置容器自启动

root@debian:/# docker run -d -p 80:5000 -v /opt/registryData:/var/lib/registry --restart=always --name localRegistry registry

3e039e259a2d03925b4a6937e1c498c568a707e99c04ce9bc29cf716ad3a40c2

root@debian:/# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

3e039e259a2d registry "/entrypoint.sh /etc…" About a minute ago Up About a minute 0.0.0.0:80->5000/tcp, :::80->5000/tcp localRegistry

5 配置私有仓库地址

root@debian:/# vi /etc/docker/daemon.json

{

"registry-mirrors": [";],

"insecure-registries": ["192.168.100.200"] ##新增

}

6 重启docker服务

root@debian:/# systemctl restart docker

root@debian:/# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

root@debian:/# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

3e039e259a2d registry "/entrypoint.sh /etc…" 10 minutes ago Up 3 seconds 0.0.0.0:80->5000/tcp, :::80->5000/tcp localRegistry

7 测试私有镜像库是否工作正常

拉取nginx镜像

root@debian:/# docker pull nginx:latest

latest: Pulling from library/nginx

a2abf6c4d29d: Pull complete

a9edb18cadd1: Pull complete

589b7251471a: Pull complete

186b1aaa4aa6: Pull complete

b4df32aa5a72: Pull complete

a0bcbecc962e: Pull complete

Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31

Status: Downloaded newer image for nginx:latest

docker.io/library/nginx:latest

标记本地nginx镜像,归入本地私有仓库

root@debian:/# docker tag nginx:latest 192.168.100.200/nginx

将镜像推送到本地私有仓库

root@debian:/# docker push 192.168.100.200/nginx

Using default tag: latest

The push refers to repository [192.168.100.200/nginx]

d874fd2bc83b: Pushed

32ce5f6a5106: Pushed

f1db227348d0: Pushed

b8d6e692a25e: Pushed

e379e8aedd4d: Pushed

2edcec3590a4: Pushed

latest: digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3 size: 1570

删除本地相关的nginx镜像

root@debian:/# docker rmi 192.168.100.200/nginx nginx

Untagged: 192.168.100.200/nginx:latest

Untagged: 192.168.100.200/nginx@sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3

Untagged: nginx:latest

Untagged: nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31

Deleted: sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85

Deleted: sha256:b625d8e29573fa369e799ca7c5df8b7a902126d2b7cbeb390af59e4b9e1210c5

Deleted: sha256:7850d382fb05e393e211067c5ca0aada2111fcbe550a90fed04d1c634bd31a14

Deleted: sha256:02b80ac2055edd757a996c3d554e6a8906fd3521e14d1227440afd5163a5f1c4

Deleted: sha256:b92aa5824592ecb46e6d169f8e694a99150ccef01a2aabea7b9c02356cdabe7c

Deleted: sha256:780238f18c540007376dd5e904f583896a69fe620876cabc06977a3af4ba4fb5

Deleted: sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f

root@debian:/# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

registry latest b8604a3fe854 12 months ago 26.2MB

从本地私有镜像库中拉取nginx镜像

root@debian:/# docker pull 192.168.100.200/nginx

Using default tag: latest

latest: Pulling from nginx

a2abf6c4d29d: Pull complete

a9edb18cadd1: Pull complete

589b7251471a: Pull complete

186b1aaa4aa6: Pull complete

b4df32aa5a72: Pull complete

a0bcbecc962e: Pull complete

Digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3

Status: Downloaded newer image for 192.168.100.200/nginx:latest

192.168.100.200/nginx:latest

root@debian:/# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

192.168.100.200/nginx latest 605c77e624dd 10 months ago 141MB

registry latest b8604a3fe854 12 months ago 26.2MB

Ok,到这里,已确认本地docker镜像仓库可正常运行

标签: #ubuntu devsda