使用ADD命令将目录复制到Docker的其他目录

本文翻译自: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参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值