在容器编译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 ~]#