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 gain bash access to a docker container after its ran
  • Is it possible to mount one Path to all container by default?
  • Increasing Docker container size on Centos
  • Elasticsearch docker burn data in image
  • Referencing a dynamic argument in the Docker Entrypoint
  • nginx error 403 - directory index is forbidden
  • 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?

  • docker custom nginx container failed to start
  • How can I run a docker container on localhost over the default IP?
  • Run AspNet Core app in docker using GMSA
  • How to restart mysql docker image with different startup parameter
  • Jenkins: Don't want to trigger on Git Tag (No Workspace)
  • NFS or mounting shares with docker
  • 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.