1 minute read

Tags: , ,

  • section5-47

Udemy




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
27f465885d3087962d0779d5638761debb3e50532a6f634a007352bbfbfea7e4
  • 看 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">
<head>
  <meta charset="utf-8">

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

</head>

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

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