查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos <none> 300e315adb2f 7 days ago 209MB
registry latest 2d4f4b5309b1 6 months ago 26.2MB
将镜像启动为容器,用它来创建本地的私有仓库
[root@localhost ~]# docker run -itd -p 5000:5000 registry
e2b974d9b078cba775d46c8c3298c0961ef4fdf890176f41e51e2bc8dc8ed3d0
私有仓库里面此时没有镜像
[root@localhost ~]# curl http://192.168.200.69:5000/v2/_catalog
{"repositories":[]}
打标签,要带有私有仓库的ip和端口
[root@localhost ~]# docker tag 300e315adb2f 192.168.200.69:5000/centos777
更改配置文件,目的把标记的镜像推送到私有仓库
[root@localhost ~]# vi /etc/docker/daemon.json
{
"registry-mirrors":["https://dhp9bx4f.mirror.aliyuncs.com"],"insecure-registries":[“192.168.200
.69:5000"]
}
~
~
~
"/etc/docker/daemon.json" 3L, 109C written
更改完后要重启
[root@localhost ~]# systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
查看registry的容器已关闭
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e2b974d9b078 registry "/entrypoint.sh /etc…" 6 minutes ago Exited (2) About a minute ago tender_proskuriakova
d2bc16e54199 300e315adb2f "/bin/bash" 2 hours ago Exited (0) About a minute ago liufengzi
开启registry容器
[root@localhost ~]# docker start e2b974d9b078
e2b974d9b078
把标记的镜像推送到私有仓库
[root@localhost ~]# docker push 192.168.200.69:5000/centos777
The push refers to repository [192.168.200.69:5000/centos777]
2653d992f4ef: Pushed
latest: digest: sha256:dbbacecc49b088458781c16f3775f2a2ec7521079034a7ba499c8b0bb7f86875 size: 529
查看是否推送成功
[root@localhost ~]# curl http://192.168.200.69:5000/v2/_catalog
{"repositories":["centos777"]}
编辑配置文件
[root@localhost ~]# vi start.sh
#!/bin/bash
httpd
while true
do
sleep
done
编辑Docker配置文件
[root@localhost ~]# vi Dockerfile
FROM 192.168.200.69:5000/centos777
MAINTAINER zuozhe
RUN yum install net-tools httpd -y
EXPOSE 80
ADD start.sh /root
RUN chmod +x /root/start.sh
CMD /root/start.sh
查看已有
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_http v1
将镜像启动
[root@localhost ~]# docker run -itd --name wangruxin -p 8888:80 6f33e96b32b2
d6c959ec03fe838f00dc12eba682f83b2d017a5e396f51259336cafed656088c
浏览器访问端口

本文详细介绍了如何使用Docker操作镜像,包括查看镜像、启动容器、创建私有仓库、打标签、推送镜像并验证。涉及到了docker run、docker tag、docker push等关键步骤。
330

被折叠的 条评论
为什么被折叠?



