Docker构建在指定Dockerfile位置时添加空目录?

时间:2019-03-05 00:42:02

标签: docker docker-compose dockerfile

使用Dockerfile从我要构建的上下文的子目录中构建映像时,我在Docker中遇到意外行为,即:

docker build -t test -f build/docker/golang/Dockerfile .

出于理智,我已从Dockerfile中删除了几乎所有内容,除了以下内容:

FROM golang:1.12-alpine3.9 AS builder
RUN apk add tree
WORKDIR /build/dir
COPY . .
RUN tree -a

然后,其中.dockerignore为:

*
!cmd
!pkg

我跑步,并获得以下输出:

$ docker build --no-cache -f build/docker/golang/Dockerfile .
Sending build context to Docker daemon  10.75kB
Step 1/5 : FROM golang:1.12-alpine3.9 AS builder
 ---> d4953956cf1e
Step 2/5 : RUN apk add tree
 ---> Running in 20bbaf5ce5b9
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/1) Installing tree (1.8.0-r0)
Executing busybox-1.29.3-r10.trigger
OK: 6 MiB in 16 packages
Removing intermediate container 20bbaf5ce5b9
 ---> f93961f78847
Step 3/5 : WORKDIR /build/dir
 ---> Running in e8637288cf26
Removing intermediate container e8637288cf26
 ---> 90473d72f983
Step 4/5 : COPY . .
 ---> aeec506ba056
Step 5/5 : RUN tree -a
 ---> Running in fa652d2cdf65
.
├── build
│   └── docker
│       └── golang
├── cmd
│   ├── api
│   │   └── main.go
│   └── worker
│       └── main.go
└── pkg
    └── math
        ├── math.go
        └── math_test.go

8 directories, 4 files
Removing intermediate container fa652d2cdf65
 ---> ef761dfd7e4e
Successfully built ef761dfd7e4e

所以,我的问题是:空的但现有的build/docker/golang目录有什么用?我可以把东西放进去,什么都不会通过,Dockerfile不在那儿,但是目录存在...空..嘲笑我。

如果我将Dockerfile移到项目的根目录(即docker build .中,则不会发生这种情况,但这并不能真正解决我的问题,因此也不是这种选择项目需求。

0 个答案:

没有答案