0

使用以下内容Dockerfile

FROM alpine:latest

WORKDIR /usr/src/app

COPY ["somefile", "/"]

build以下命令:

docker build \
--file=Dockerfile \
--no-cache=true \
--progress=plain \
--tag=someimage:sometag \
.

=>

#1 [internal] load build definition from Dockerfile
. . .
#8 naming to docker.io/someimage:sometag done
#8 DONE 0.0s

为什么somefile在根 ( /) 中找到:

docker run someimage:sometag ls -altr ../../../.

#=>

total 68
. . .
-rw-r--r--    1 root     root           128 Jul 27 12:34 somefile
. . .
drwxr-xr-x    1 root     root          4096 Jul 27 12:34 ..
drwxr-xr-x    1 root     root          4096 Jul 27 12:34 .

而不是工作目录 ( /usr/src/app):

docker run someimage:sometag ls -altr .

#=>

total 8
drwxr-xr-x    3 root     root          4096 Jul 27 12:34 ..
drwxr-xr-x    2 root     root          4096 Jul 27 12:34 .
4

1 回答 1

0

您的COPY说明Dockerfile

. . .
COPY ["somefile", "/"]
. . .

使用绝对路径而不是相对路径;更多关于这里

替换/./will COPY somefileto/usr/src/app而不是根目录:

FROM alpine:latest

WORKDIR /usr/src/app

COPY ["somefile", "./"]

我们可以通过以下方式定位somefile图像build

docker run someimage:anothertag ls -altr .

#=>

total 16
-rw-r--r--    1 root     root           128 Jul 27 23:45 somefile
drwxr-xr-x    1 root     root          4096 Jul 27 23:45 ..
drwxr-xr-x    1 root     root          4096 Jul 27 23:45 .
于 2021-07-28T00:11:23.463 回答