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

  • How to fix cadvisor error `devicemapper filesystem stats will not be reported`?
  • How do I mount a host directory as a volume in docker compose
  • Docker: How to access to a private github repo using ssh?
  • Using MySQL with Spring boot docker image
  • Accessing a MariaDB in one Docker from another Docker
  • Why are there differences in docker pull and docker build in IBM Container Service?
  • 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?

  • Cgroups report weird cpu and memory usage
  • Pycharm 2017 docker support for debugging
  • graphql and serverless offline running in docker
  • cannot open connection of database in docker
  • can't authenticate user in postgres docker container
  • Docker mysql_connect(): Can't connect
  • 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.