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

  • Can't change directories in a docker container?
  • Dockerfile ADD doesn't work
  • What is the best practice of docker + ufw under Ubuntu
  • Why can't I curl one docker container from another via the host
  • Starting mongo through docker on a Synology NAS
  • Sails doesnt populate on large queries
  • 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?

  • cannot connect to docker on RemoteServer using Ansible
  • Update Jupyter to Python 3.4 in default Tensorflow docker container
  • How to select volume mountpoint in docker-compose.yml?
  • How to access to a file in docker container already exit?
  • How can I specify an Alternate Exposed Port for Redis / RethinkDB (using Docker Compose)?
  • PostgreSQL UNIQUE constraint not being applied on Docker 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.