利用Docker volume修改Nginx Docker镜像里index.html
生活随笔
收集整理的這篇文章主要介紹了
利用Docker volume修改Nginx Docker镜像里index.html
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通過這個小例子我們可以進一步加深對Docker volume概念的理解和使用方法。
我們都知道運行基于Docker的Nginx鏡像后,訪問localhost能看到Nginx默認的首頁,這個首頁的位置是Nginx鏡像內的/usr/share/nginx/html目錄下面。
假設我們有個需求,修改Nginx默認的首頁成下面的內容:
<html> <head> <title>Custom Website from my container</title> </head> <body> <h1>This is Jerry's custom website.</h1> <p>This website is served from my <a href="http://www.docker.com" target="_blank">SAP Docker</a> container.</p> </body> </html>下面是詳細方法。
命令行-v將主機目錄nginx-html掛載到Nginx容器內的/usr/share/nginx/html目錄內。
docker run -d -p 1081:80 -v `pwd`/nginx-html:/usr/share/nginx/html --name jerry-custom nginx使用vi將主機目錄nginx-html下面的index.html修改成自定義內容:
通過交互式的方式進入到docker容器內部:
docker exec -it jerry-custom /bin/sh發現Docker容器里的index.html也自動被修改了,內容和主機目錄nginx-html下面的一致。
localhost:1081即可看到修改過后的自定義Nginx首頁:
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的利用Docker volume修改Nginx Docker镜像里index.html的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP C4C里如何实现Sales Un
- 下一篇: Docker镜像提交命令commit的工