43

I'm having in Dockerfile:

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

and .dockerignore file:

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

However, once showing files in the built container, I can see also those that are supposed to be ignored:

/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 

How can I achieve having all those mentioned in the .dockerignore file ignored?

2 Answers 2

27

The .dockerignore rules follow the filepath/#Match.

Try (for testing) Gemfile.lock instead of /Gemfile.lock.

And check that the eol (end of line) characters are unix-style, not Windows style in your .dockerignore file.

Apparently, (docker 1.10, March 2016) using rule starting with / like /xxx ( or /.*) is not well supported.

Sign up to request clarification or add additional context in comments.

16 Comments

I checked and I have unix encoding, moreover I tried with Gemfile.lock, didn't help. Any further hints? Full code is available on: github.com/datarator/datarator , moreover, the docker image is: datarator/datarator:edge
@PeterButkovic What docker version are tou using? On which OS?
locally: docker: Docker version 1.10.3, build 20f81dd OS: RHEL 7.2, however I have it also running in the travis infrastructure, same problem on both sides.
@PeterButkovic following github.com/docker/docker/issues/17911, can you try without the /.* in your .dockerignore? (just for testing)
OK, interesting, I've found the following points (regardless of COPY or ADD): using root slash doesn't work for me (=> file/dir is added anyway), moreover I had some weird issues I can't reproduce any more (single Gemfile.lock works OK now), @VonC: your answer seems right :) Thanks for your patient support!
|
4

Here's the complete syntax for the .dockerignore:

pattern: { term } term: '*' matches any sequence of non-Separator characters '?' matches any single non-Separator character '[' [ '^' ] { character-range } ']' character class (must be non-empty) c matches character c (c != '*', '?', '\\', '[') '\\' c matches character c character-range: c matches character c (c != '\\', '-', ']') '\\' c matches character c lo '-' hi matches character c for lo <= c <= hi additions: '**' matches any number of directories (including zero) '!' lines starting with ! (exclamation mark) can be used to make exceptions to exclusions '#' lines starting with this character are ignored: use it for comments 

Therefore, some of your matches would be changed according to the above syntax:

/Gemfile.lock --> */Gemfile.lock or **/Gemfile.lock or *.lock /spec --> */spec or **/spec /tmp --> in the same way /log --> in the same way 

Here are two articles to explain more:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.