【问题标题】:.dockerignore mentioned files are not ignored.dockerignore 提到的文件不会被忽略
【发布时间】:2016-03-30 15:07:06
【问题描述】:

我在Dockerfile:

ENV DATARATOR_HOME /usr/local/share/datarator
RUN mkdir -p $DATARATOR_HOME
COPY . $DATARATOR_HOME

.dockerignore 文件:

/Gemfile.lock
/coverage
/spec
*.bundle
*.so
*.o
*.a
mkmf.log
*.swp
/.*
/tmp
/log

但是,一旦在构建的容器中显示文件,我也可以看到那些应该被忽略的文件:

/usr/local/share/datarator # ls -lha
total 128
drwxr-xr-x   10 root     root        4.0K Mar 29 21:01 .
drwxr-xr-x    4 root     root        4.0K Mar 29 21:00 ..
drwxr-xr-x    2 root     root        4.0K Mar 29 21:01 .bundle
-rw-rw-r--    1 root     root          24 Mar 29 20:37 .coveralls.yml
-rw-rw-r--    1 root     root          81 Mar 29 20:37 .dockerignore
drwxrwxr-x    8 root     root        4.0K Mar 29 20:37 .git
-rw-rw-r--    1 root     root          85 Mar 29 20:37 .gitignore
-rw-rw-r--    1 root     root        1.2K Mar 29 20:37 .travis.yml
-rw-rw-r--    1 root     root         509 Mar 29 20:37 .vimrc
-rw-rw-r--    1 root     root         959 Mar 29 20:37 Dockerfile
-rw-rw-r--    1 root     root          94 Mar 29 20:37 Gemfile
-rw-r--r--    1 root     root        2.7K Mar 29 21:01 Gemfile.lock
-rw-rw-r--    1 root     root         343 Mar 29 20:37 Guardfile
-rw-rw-r--    1 root     root        1.0K Mar 29 20:37 LICENSE.txt
-rw-rw-r--    1 root     root          71 Mar 29 20:37 Procfile
-rw-rw-r--    1 root     root       14.8K Mar 29 20:37 README.md
-rw-rw-r--    1 root     root         198 Mar 29 20:37 Rakefile
drwxrwxr-x    2 root     root        4.0K Mar 29 20:37 bin
drwxrwxr-x    2 root     root        4.0K Mar 29 20:37 config
-rw-rw-r--    1 root     root          97 Mar 29 20:37 config.ru
-rw-r--r--    1 root     root       16.0K Mar 29 21:01 datarator-0.0.1.gem
-rw-rw-r--    1 root     root        1.7K Mar 29 20:37 datarator.gemspec
drwxrwxr-x    4 root     root        4.0K Mar 29 20:37 lib
drwxrwxr-x    2 root     root        4.0K Mar 29 20:37 log
drwxrwxr-x    3 root     root        4.0K Mar 29 20:37 spec
drwxrwxr-x    2 root     root        4.0K Mar 29 20:37 tmp

如何实现忽略.dockerignore 文件中提到的所有内容?

【问题讨论】:

    标签: docker dockerfile


    【解决方案1】:

    .dockerignore 规则遵循filepath/#Match

    尝试(用于测试)Gemfile.lock 而不是 /Gemfile.lock

    并检查 .dockerignore 文件中的 eol(行尾)字符是否为 unix 样式,而不是 Windows 样式。

    显然,(docker 1.10,2016 年 3 月)使用以 / 开头的规则,例如 /xxx(或 /.*is not well supported

    【讨论】:

    • 我检查了,我有 unix 编码,而且我尝试使用Gemfile.lock,没有帮助。任何进一步的提示?完整代码在:github.com/datarator/datarator,此外,docker 镜像为:datarator/datarator:edge
    • @PeterButkovic 你用的是什么 docker 版本?在哪个操作系统上?
    • 本地:docker:Docker version 1.10.3, build 20f81dd OS:RHEL 7.2,但是我也有它在 travis 基础架构中运行,双方都有同样的问题。
    • @PeterButkovic 关注github.com/docker/docker/issues/17911,您可以尝试在.dockerignore 中不使用/.* 吗? (仅用于测试)
    • 好的,有趣的是,我发现了以下几点(无论是 COPY 还是 ADD):使用根斜线对我不起作用(=> 无论如何添加了文件/目录),而且我有一些我无法再重现的奇怪问题(单个Gemfile.lock 现在可以正常工作),@VonC:您的回答似乎正确 :) 感谢您的耐心支持!
    猜你喜欢
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2022-07-14
    • 2019-07-14
    • 2018-06-29
    • 1970-01-01
    • 2018-09-17
    相关资源
    最近更新 更多