gpt4 book ai didi

docker - dockerfile可以放在.dockerignore中吗?

转载 作者:IT老高 更新时间:2023-10-28 21:22:16 25 4
gpt4 key购买 nike

文档说可以。

https://docs.docker.com/engine/reference/builder/

You can even use the .dockerignore file to exclude the Dockerfile and .dockerignore files. These files are still sent to the daemon because it needs them to do its job. But the ADD and COPY instructions do not copy them to the image.

但是当我将 dockerfile 放入 .dockerignore 时,我得到了

Sending build context to Docker daemon  1.646MB
Error response from daemon: Cannot locate specified Dockerfile: Dockerfile

最佳答案

是的,你可以;你甚至可以把 .dockerignore 本身扔进去!

您可能做了其他不正确的事情 - 可能在错误的目录中?

目录列表:

➜  ls -la
total 16
drwxr-xr-x 4 tj wheel 128 Nov 30 13:42 .
drwxrwxrwt 7 root wheel 224 Nov 30 13:42 ..
-rw-r--r-- 1 tj wheel 26 Nov 30 13:41 .dockerignore
-rw-r--r-- 1 tj wheel 28 Nov 30 13:42 Dockerfile

文件内容:

➜  cat .dockerignore
.dockerignore
Dockerfile

➜ test_docker_ignore cat Dockerfile
FROM ubuntu:16.04
ADD . .

构建一次;将 --no-cache 指定为详细:

➜  docker build -t test --no-cache .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM ubuntu:16.04
---> 20c44cd7596f
Step 2/2 : ADD . .
---> 4d8ded297954
Successfully built 4d8ded297954
Successfully tagged test:latest

Dockerfile 添加一些内容并重建:构建将使用缓存,因为它忽略了对 Dockerfile

所做的更改
➜  echo "# A Test Comment" >> Dockerfile
➜ docker build -t test .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM ubuntu:16.04
---> 20c44cd7596f
Step 2/2 : ADD . .
---> Using cache
---> 4d8ded297954
Successfully built 4d8ded297954
Successfully tagged test:latest

关于docker - dockerfile可以放在.dockerignore中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47580298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com