Dockerfile-httpd

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

查看镜像

[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

浏览器访问端口
在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值