利用Docker volume修改Nginx Docker映象裡index.html
阿新 • • 發佈:2018-11-27
通過這個小例子我們可以進一步加深對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的原創文章,請關注公眾號"汪子熙":