一看必会系列:dockerfile 练习2 创建apache镜像

来源:本站原创 Docker 超过37 views围观 0条评论

 

新建目录及文件
/opt/dockerfile/httpd_2.4
├── httpd_2.4
│   ├── dockerfile
│   ├── httpd.conf
│   └── public-html
│       └── index.html

index.html 内容
<h1>jeff dockerfile apache</h1>

dockerfile 内容
FROM httpd:2.4   #基础镜像名
COPY ./public-html/ /usr/local/apache2/htdocs/  #复制目录文件到 容器内目录

生成镜像
root@docker:/opt/dockerfile/httpd_2.4# docker build -t httpd_jeff:1.0.0 .
Sending build context to Docker daemon  26.11kB
Step 1/2 : FROM httpd:2.4
—> 2d1e5208483c
Step 2/2 : COPY ./public-html/ /usr/local/apache2/htdocs/
—> 46af319543cf
Successfully built 46af319543cf
Successfully tagged httpd_jeff:1.0.0

验证镜像
root@docker:/opt/dockerfile/httpd_2.4# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
httpd_jeff                        1.0.0               46af319543cf        8 minutes ago       132MB

运行镜像  -i 交互模式 -t 伪终端 -d 后台运行
root@docker:/opt/dockerfile/httpd_2.4# docker run -itd  –name httpd_jeff -p 8080:80 httpd_jeff:1.0.0
504df67c3fecea806c39338c82f4440e4797b79e9cad6d332da1750ec6e63fc0

root@docker:/opt/dockerfile/httpd_2.4# docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                  NAMES
504df67c3fec        httpd_jeff:1.0.0    "httpd-foreground"   5 seconds ago       Up 3 seconds        0.0.0.0:8080->80/tcp   httpd_jeff

验证
root@docker:/opt/dockerfile/httpd_2.4# curl 192.168.10.67:8080
<h1>jeff dockerfile apache</h1>
以上信息为正常

 

报错解决
root@docker:/opt/dockerfile/httpd_2.4# docker run -it –rm –name my-running-app -p 8081:80 apache2.4-images:001
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 192.169.110.10. Set the ‘ServerName’ directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 192.169.110.10. Set the ‘ServerName’ directive globally to suppress this message
[Thu Mar 14 04:10:23.728775 2019] [mpm_event:notice] [pid 1:tid 139725533614144] AH00489: Apache/2.4.38 (Unix) configured — resuming normal operations
[Thu Mar 14 04:10:23.728982 2019] [core:notice] [pid 1:tid 139725533614144] AH00094: Command line: ‘httpd -D FOREGROUND’
[Thu Mar 14 04:10:23.821551 2019] [mpm_event:notice] [pid 1:tid 139725533614144] AH00492: caught SIGWINCH, shutting down gracefully

修改

root@c76876b5237f:/usr/local/apache2# sed -i "s/#ServerName www.example.com:80/ServerName 0.0.0.0:80/g" /usr/local/apache2/conf/httpd.conf
root@c76876b5237f:/usr/local/apache2# !c
cat conf/httpd.conf |grep Name
# ServerName gives the name and port that the server uses to identify itself.
ServerName 0.0.0.0:80
root@c76876b5237f:/usr/local/apache2#

root@docker:/opt/dockerfile/httpd_2.4# docker run -it –rm –name my-running-app -p 8081:80 apache2.4-images:003[Thu Mar 14 04:12:06.933813 2019] [mpm_event:notice] [pid 1:tid 139627409084480] AH00489: Apache/2.4.38 (Unix) configured — resuming normal operations
[Thu Mar 14 04:12:06.933976 2019] [core:notice] [pid 1:tid 139627409084480] AH00094: Command line: ‘httpd -D FOREGROUND’
[Thu Mar 14 04:12:07.022337 2019] [mpm_event:notice] [pid 1:tid 139627409084480] AH00492: caught SIGWINCH, shutting down gracefully

 

停止所有容器
  docker stop $(docker ps|awk ‘{print $1}’)
删除所有容器
docker rm $(docker ps -a|awk ‘{print $1}’)
删除所有镜像
docker rmi -f $(docker images |grep dockerfile|awk ‘{print $3}’)

 

https://hub.docker.com/_/httpd?tab=description

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=4083转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

您必须 [ 登录 ] 才能发表留言!