How to specify different .dockerignore files for different builds in the same project?

I used to list the tests directory in .dockerignore so that it wouldn’t get included in the image, which I used to run a web service.

Now I’m trying to use Docker to run my unit tests, and in this case I want the tests directory included.

  • Accessing docker container IP from a different physical machine
  • Can't reach localhost:8080 while running docker image
  • How to link to additional container without restarting?
  • centos6.6 in Dockerfile gives error
  • Assigning IP address to docker containers?
  • Docker “/bin/bash” could not be invoked when mounting an NFS file with -v on openstack
  • I’ve checked docker build -h and found no option related.

    How can I do this?

  • how to properly build spring boot docker image using Dockerfile?
  • How to create a copy of exisiting docker image
  • System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.0.0
  • SQL Server on Mac with Docker : Login failed for user 'sa'.
  • Migrating from shared development database to single database for each developer
  • How does docker image size impact runtime characteristics?
  • One Solution collect form web for “How to specify different .dockerignore files for different builds in the same project?”

    At the moment, there is no way to do this. There is a lengthy discussion about adding an --ignore flag to Docker to provide the ignore file to use – please see here.

    The options you have at the moment are mostly ugly:

    • Split your project into subdirectories that each have their own Dockerfile and .dockerignore, which might not work in your case.
    • Create a script that copies the relevant files into a temporary directory and run the Docker build there.
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.