1 minute read

Tags: , ,

  • section5-47


Persisten Data: Bind Mounting

  • Maps a host file or directory to a container file or directory
  • Basically just tow locations pointing to the same files(s)
  • Again, skips UFS, and host files overwrite any in container
  • Can’t use in Dockerfile, must be at container run

  • ... run -v /Users/bret/stuff:/path/container (max/linux)
  • ... run -v //c/Users/bret/stuff:/path/container (windows)

Binde to local machine …

照著打… 不知道為甚麼 都是 403 Forbidden ….

有爬文,好像跟 index.html 的權限設定有關西 LOL

  • 有成功的話,這nginx container 會抓我 local 端資料夾下面的 index.html 吐回給 user 呈現

    • 但我怎麼 try 都GG~~~
 docker container run -d --name nginx -p 80:80 -v //e/Udemy/"Docker Mastery"/udemy-docker-mastery/dockerfile-sample-2:/usr/share/nginx/html nginx



  • Run Container
PS E:\> docker container run -d --name nginx -p 80:80 -v e:/Udemy/"Docker Mastery"/udemy-docker-mastery/dockerfile-sample-2:/usr/share/nginx/html nginx
  • 看 Container 裡面的 路徑
PS E:\> docker container exec -it nginx bash
root@27f465885d30:/# cd /usr/share/nginx/html
root@27f465885d30:/usr/share/nginx/html# ls
Dockerfile  index.html
root@27f465885d30:/usr/share/nginx/html# cat index.html
<!doctype html>
<html lang="en">
  <meta charset="utf-8">

  <title>Your 2nd Dockerfile worked!</title>


  <h1>You just successfully ran a container with a custom file copied into the image at build time!</h1>
root@27f465885d30:/usr/share/nginx/html# exit
PS E:\> docker container run -d -p 8080:80 --name nginx2 nginx

開心 :heart: 又一次的學習~