加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

dockerfile可以放入.dockerignore吗?

发布时间:2020-12-16 03:45:52 所属栏目:安全 来源:网络整理
导读:文档说是的,它可以. 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. B

文档说是的,它可以.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读