如何从本机传送一个目录到docker image中
伊谢尔伦
伊谢尔伦 2017-04-21 11:15:18
0
3
747

通过build docker image 添加文件时,需要用到ADD或COPY关键字,但是ADD或COPY后面跟的只能是相对于Dockerfile文件所在的目录的路径的目录或文件,有没有一种方法可以通过绝对路径来传送目录或文件?(貌似docker里面有一个cp命令,但是只能从container中复制文件或目录到本机中,并不能从本机到container中。(为什么??))

伊谢尔伦
伊谢尔伦

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

reply all(3)
小葫芦

You can use the data volume function to mount the host’s directory into the container

黄舟
  1. The ADDCOPY command in Dockerfile cannot use absolute paths, only relative paths. This is stated clearly in the official documentation 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. If you don’t have to build the files into the image, you can use the -v parameter when running the container to load/share the host file or directory into the container. Reference https://docs.docker.com/userguide/dockervolumes/#mount-a-host-directory-as-a-data-volume

洪涛

Docker’s cp command can copy out of the container or copy the container from the local machine.

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.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template