本文翻译自:Copy directory to other directory at Docker using ADD command
I have read http://docs.docker.com/engine/reference/builder/#add however I met a problem. 我已阅读http://docs.docker.com/engine/reference/builder/#add但我遇到了一个问题。 I want to copy the local directory go
to docker /user/local/
我想复制本地目录go
docker /user/local/
I tried: 我试过了:
ADD go /usr/local/
and: 和:
ADD /go/ /usr/local/
also: 也:
RUN chmod 0755 /usr/local/go/src/make.bash
However, I see the following error message /usr/local/go/src/make.bash: No such file or directory
but the local go
directory does contain make.bash
. 但是,我看到以下错误消息/usr/local/go/src/make.bash: No such file or directory
但本地go
目录确实包含make.bash
。
#1楼
参考:https://stackoom.com/question/1nD7W/使用ADD命令将目录复制到Docker的其他目录
#2楼
ADD go /usr/local/
will copy the contents of your local go
directory in the /usr/local/
directory of your docker image. 将在docker镜像的/usr/local/
目录中复制本地go
目录的内容 。
To copy the go
directory itself in /usr/local/
use: 要在/usr/local/
use中复制go
目录本身:
ADD go /usr/local/go
or 要么
COPY go /usr/local/go
#3楼
Indeed ADD go /usr/local/
will add content of go
folder and not the folder itself, you can use Thomasleveil solution or if that did not work for some reason you can change WORKDIR
to /usr/local/
then add your directory to it like: 确实ADD go /usr/local/
会添加go
文件夹的内容而不是文件夹本身,你可以使用Thomasleveil解决方案,或者如果由于某种原因无效,你可以将WORKDIR
更改为/usr/local/
然后将你的目录添加到它喜欢:
WORKDIR /usr/local/
COPY go go/
or 要么
WORKDIR /usr/local/go
COPY go ./
But if you want to add multiple folders, it will be annoying to add them like that, the only solution for now as I see it from my current issue is using COPY . .
但是如果你想添加多个文件夹,那么添加它们会很烦人,现在唯一的解决方案是我现在的问题是使用COPY . .
COPY . .
and exclude all unwanted directories and files in .dockerignore
, let's say I got folders and files: 并排除.dockerignore
所有不需要的目录和文件,假设我有文件夹和文件:
src
tmp
dist
assets
go
justforfun
node_modules
scripts
.dockerignore
Dockerfile
headache.lock
package.json
and I want to add src assets package.json justforfun go
so: 我想添加src assets package.json justforfun go
so:
in Dockerfile: 在Dockerfile中:
FROM galaxy:latest
WORKDIR /usr/local/
COPY . .
in .dockerignore file: 在.dockerignore文件中:
node_modules
headache.lock
tmp
dist
Or for more fun (or you like to confuse more people make them suffer as well :P) can be: 或者为了更多的乐趣(或者你想让更多的人迷惑让他们受苦:P)可以是:
*
!src
!assets
!go
!justforfun
!scripts
!package.json
In this way you ignore everything, but excluding what you want to be copied or added only from "ignore list". 通过这种方式,您可以忽略所有内容,但不包括您希望复制或仅从“忽略列表”添加的内容。
It is a late answer but adding more ways to do the same covering even more cases. 这是一个迟到的答案,但增加了更多的方法,以覆盖更多的情况。
#4楼
You can use COPY. 您可以使用COPY。 You need to specify the directory explicitly. 您需要明确指定目录。 It won't be created by itself 它不会自己创建
COPY go /usr/local/go
Reference: Docker CP reference 参考: Docker CP参考