远程测试私有仓库registry
<h1>环境</h1>
<p>测试端机器 (主机名为192.168.1.10):远程测试私有仓库服务器
测试镜像仓库(测试端操作)</p>
<h1>下载busybox镜像</h1>
<pre><code>docker pull busybox</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/c00639bb7335b65699516cdd1a52870e?showdoc=.jpg" alt="" /></p>
<pre><code>docker images</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/902268883a3eaea6c9310d1e7945c3e1?showdoc=.jpg" alt="" /></p>
<h2>镜像打标签</h2>
<pre><code>docker tag busybox:latest 192.168.1.2:5000/busybox:v1</code></pre>
<p>格式说明:Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] </p>
<p>busybox:lastest 这是源镜像,也是刚才pull下来的镜像文件;
192.168.1.2:5000/busybox:v1:这是目标镜像,也是registry私有镜像服务器的IP地址和端口;</p>
<h2>查看tag</h2>
<pre><code>docker images</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/df52f4dd98dd5142367df8315bdacab1?showdoc=.jpg" alt="" /></p>
<h2>上传镜像</h2>
<pre><code>docker push 192.168.1.2:5000/busybox:v1 </code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/5220b7102c40647066c10ba02afcccde?showdoc=.jpg" alt="" /></p>
<p>注意了,这是报错了,需要https的方法才能上传,我们可以修改下daemon.json来解决:</p>
<p>vim /etc/docker/daemon.json </p>
<pre><code>{
"registry-mirrors": ["http://f2d6cb40.m.daocloud.io","http://hub-mirror.c.163.com","https://registry.cn-shenzhen.aliyuncs.com"],
"insecure-registries": ["192.168.1.20:5000"]
}</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/e0a4ab2e36a8001ca2ade1cd70c719af?showdoc=.jpg" alt="" />
添加私有镜像服务器的地址,注意书写格式为json,有严格的书写要求,然后重启docker服务:</p>
<pre><code>systemctl restart docker</code></pre>
<h2>在次上传</h2>
<pre><code>docker push 192.168.1.2:5000/busybox:v1</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/9506a90ef9d21c5d19cd61f590074156?showdoc=.jpg" alt="" /></p>
<h1>下载镜像</h1>
<h2>先删除主机上的镜像:</h2>
<pre><code>docker rmi -f $(docker images -aq)</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/40f81753b54c3019bd6fba02b41b537e?showdoc=.jpg" alt="" /></p>
<h2>查看一下主机上的镜像全部删除了:</h2>
<pre><code>docker images</code></pre>
<h2>然后,从registry服务器上下载busybox镜像:</h2>
<pre><code>docker pull 192.168.1.2:5000/busybox:v1</code></pre>
<h2>检查是否下载到镜像</h2>
<pre><code>docker images</code></pre>
<h1>列出服务器上所有镜像</h1>
<pre><code>curl http://192.168.1.2:5000/v2/_catalog</code></pre>
<h1>查看docker系统占用空间</h1>
<pre><code> docker system df</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/be01a82f7851b67d29710be53c80f849" alt="" /></p>
<h1>自动清理空间</h1>
<pre><code> docker system prune -a -f</code></pre>
<p>该指令默认会清除所有如下资源:
已停止的容器(container)
未被任何容器所使用的卷(volume)
未被任何容器所关联的网络(network)
所有悬空镜像(image)。
该指令默认只会清除悬空镜像,未被使用的镜像不会被删除。
添加 -a 或 --all 参数后,可以一并清除所有未使用的镜像和悬空镜像。
可以添加 -f 或 --force 参数用以忽略相关告警确认信息。
指令结尾处会显示总计清理释放的空间大小。</p>