Bind Mount文件夾映射在實際開發中的應用
1.編寫HTML頁面
- 在本機創建目錄 /root/webapp
- 新建index.html
<html>
<h1>
Docker is very Good!
</h1>
</html>
2.啓動容器
docker run -d --name=nginx_web -v /root/webapp:/usr/share/nginx/html -p=80:80 nginx:latest
我們本地的項目路徑是/root/webap,nginx默認的顯示路徑是/usr/share/nginx/html/,所以使用bing mounting來將兩個路徑做映射。
這樣就能達到在本地修改代碼,docker中的代碼就會同步改變。