如何從本機傳送一個目錄到docker image中
伊谢尔伦
伊谢尔伦 2017-04-21 11:15:18
0
3
820

通過build docker image 添加文件時,需要用到ADD或COPY關鍵字,但是ADD或COPY後麵跟的隻能是相對於Dockerfile文件所在的目錄的路徑的目錄或文件,有沒有一種方法可以通過絕對路徑來傳送目錄或文件?(貌似docker裏麵有一個cp命令,但是隻能從container中複製文件或目錄到本機中,並不能從本機到container中。(為什麼??))

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回覆(3)
小葫芦

可以用資料磁碟區功能將主機的目錄掛載到容器裡

黄舟
  1. Dockerfile 中 ADDCOPY 指令不能使用絕對路徑,只能使用相對路徑。這點在官方文件中所說的比較清楚https://docs.docker.com/reference/builder/#add 。

    Multiple resource may be specified but if they are files or directories then they must be relative to the source directory that is being built (the context of the build).

  2. 如果不是要把檔案 build 到 image裡,可以透過 run container 的時候透過 -v 參數將 host 檔案或目錄載入/共用到 container 裡。 參考 https://docs.docker.com/userguide/dockervolumes/#mount-a-host-directory-as-a-data-volume

洪涛

docker 的cp指令可以從容器往外複製,也可以從本機複製的容器。

docker cp more.log e7de404c00bd:/tmp/

docker help cp

Usage:    docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|-
    docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH

Copy files/folders between a container and your host.
Use '-' as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use '-' as the destination to stream a tar archive of a
container source to stdout.
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板