在容器编译httpd并能访问web站点

在容器编译httpd并能访问web站点

已经在容器里编译好了httpd(详情查看前面文章)

编译好httpd后制作镜像

[root@localhost ~]# docker commit -p -c 'CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]' k1 db9f4b637b59/httpd:v0.2
sha256:f3b8806b7c735ac72b792cbbd2cdbfb02a3adc4ab38778ed40d5923b196953b0
[root@localhost ~]# 
[root@localhost ~]# docker images
REPOSITORY           TAG       IMAGE ID       CREATED              SIZE
db9f4b637b59/httpd   v0.2      f3b8806b7c73   About a minute ago   762MB

运行一下

[root@localhost ~]# docker run -d --name web -p 80:80 -v /root/html/:/usr/local/apache/htdocs k1 nuanchun/httpd:v0.3
d909ccbfcf1416418ded3a373352ad59d3e28b956b5e278e95651929b2f3c0e5
[root@localhost ~]# 
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                     COMMAND                  CREATED             STATUS             PORTS                               NAMES
d909ccbfcf14   db9f4b637b59/httpd:v0.2   "/usr/local/apache/b…"   25 minutes ago      Up 25 minutes      0.0.0.0:80->80/tcp, :::80->80/tcp   web
db9f4b637b59   centos                    "/bin/bash"              About an hour ago   Up About an hour                                       k1
[root@localhost ~]# 

查看是否能访问到

[root@localhost ~]# echo "tatum" > html/index.html
[root@localhost ~]# curl 127.0.0.1
tatum
[root@localhost ~]# 

在这里插入图片描述

导入源码

[root@localhost ~]# cd html/
[root@localhost html]# ls
index.html
[root@localhost html]# rm -rf index.html 
[root@localhost html]# ls
 HandyEditor.min.js   index.html   skin
 external             lang        ''$'\350\257\264\346\230\216''.htm'
[root@localhost html]# 

在这里插入图片描述

再次访问

在这里插入图片描述

上传镜像

上传时记得先登录

[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: nuanchun
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@localhost ~]# 
[root@localhost ~]# docker push nuanchun/httpd:v0.3
The push refers to repository [docker.io/nuanchun/httpd]
d8c97b13275a: Pushed 
74ddd0ec08fa: Mounted from nuanchun/httpd3 
v0.3: digest: sha256:766aa76228597713edb9d6d407251a7e7a9656ffe8fc69141e097535240fef46 size: 742
[root@localhost ~]# 

在这里插入图片描述

拉镜像下来运行

[root@localhost ~]# docker pull nuanchun/httpd:v0.3
v0.3: Pulling from nuanchun/httpd
a1d0c7532777: Pull complete 
d9fa2aded6ad: Pull complete 
Digest: sha256:766aa76228597713edb9d6d407251a7e7a9656ffe8fc69141e097535240fef46
Status: Downloaded newer image for nuanchun/httpd:v0.3
docker.io/nuanchun/httpd:v0.3
[root@localhost ~]# docker run -d --name web -p 80:80 -v /root/html/:/usr/local/apache/htdocs  nuanchun/httpd:v0.3
4019d4cbf8d0e7733e4f322055caeb3e93a07ffac3cdc9f8e182e98d8e0b0c31
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                               NAMES
4019d4cbf8d0   nuanchun/httpd:v0.3   "/usr/local/apache/b…"   6 seconds ago   Up 5 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   web
[root@localhost ~]# 

再次访问

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值