一看必會系列:dockerfile 練習2 創建apache鏡像

來源:本站原創 Docker 超過324 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/  #復制目錄文件到 容器內目錄

生成鏡像
[email protected]:/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

驗證鏡像
[email protected]:/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 后臺運行
[email protected]:/opt/dockerfile/httpd_2.4# docker run -itd  –name httpd_jeff -p 8080:80 httpd_jeff:1.0.0
504df67c3fecea806c39338c82f4440e4797b79e9cad6d332da1750ec6e63fc0

[email protected]:/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

驗證
[email protected]:/opt/dockerfile/httpd_2.4# curl 192.168.10.67:8080
<h1>jeff dockerfile apache</h1>
以上信息為正常

 

報錯解決
[email protected]:/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

修改

[email protected]:/usr/local/apache2# sed -i "s/#ServerName www.example.com:80/ServerName 0.0.0.0:80/g" /usr/local/apache2/conf/httpd.conf
[email protected]:/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
[email protected]:/usr/local/apache2#

[email protected]:/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.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=4083轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
暫時還木有人評論,坐等沙發!
發表評論

您必須 [ 登錄 ] 才能發表留言!

?
?
萌宠夺宝游戏