Ignoring subfolders not working

I’m using a .dockerignore file that looks like this:


so here what I’m saying is: ignore all files in the current directory (this post is related to: How to include local libraries in build?) except for www, app and inc and ignore all directories named node_modules and bower_components in those subdirectories

  • Emulating Raspberry Pi with Docker on OS X
  • I run the tomcat in Docker but when I close the terminal it stops, so how to make it run continuous
  • Docker refusing connection
  • Run apache in both host machine and docker container on 80 port
  • how docker container can get IP where docker swarm runs
  • Hadoop (yarn) control resource consumption (CPU and RAM), on docker
  • when I run a build:

    build --no-cache -t test -f app/Dockerfile .

    (here’s my Dockerfile):

    FROM node:latest
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    ADD . /usr/src/app/

    and then run a container:

    run -i --entrypoint=/bin/bash test

    if I look in the directory I see node_modules folders!

    # ls -alF
    total 20
    drwxr-xr-x  5 root root 4096 Mar 19 03:39 ./
    drwxr-xr-x  4 root root 4096 Mar 19 03:39 ../
    drwxr-xr-x  4 root root 4096 Mar 18 03:26 inc/
    drwxr-xr-x  3 root root 4096 Mar 19 00:57 app/
    drwxr-xr-x 12 root root 4096 Mar 18 08:55 www/
    # ls -alF app
    total 36
    drwxr-xr-x   3 root root 4096 Mar 19 00:57 ./
    drwxr-xr-x   5 root root 4096 Mar 19 03:39 ../
    -rw-r--r--   1 root root   38 Mar 19 00:57 .dockerignore
    -rw-r--r--   1 root root  359 Mar 19 03:37 Dockerfile
    -rw-r--r--   1 root root  700 Mar 18 04:50 config.json
    -rw-r--r--   1 root root 3786 Mar 18 03:43 index.js
    drwxr-xr-x 119 root root 4096 Mar 17 18:57 node_modules/
    -rw-r--r--   1 root root 2910 Mar 17 20:51 npm-debug.log
    -rw-r--r--   1 root root  348 Mar 19 03:24 package.json

    so the first line of the .dockerignore worked fine, as did the 4th, 5th and 6th lines, but the subdirectories failed. for the sake of completeness I originally used **/node_modules but that failed too.

    what is the correct way of expressing this?

  • keep Guard running inside a docker container
  • Docker exits immediately after run. However, Kitematic runs without issue
  • Is it possible to install only the docker cli and not the daemon
  • Docker compose - share volume Nginx
  • Sentry Docker Port 80
  • is it considered bad practice to create ssh key in container?
  • One Solution collect form web for “Ignoring subfolders not working”

    ok, apparently the problem is that when I create exceptions to the ignore rules, I have to reapply the exceptions, so if I do this instead:


    it works because */node_modules applies to “all of the above”, which includes app. in my original declaration I was excluding the directories I do want to include from the rules

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.