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.

  • Jenkins does not run automatically after install in Docker container
  • Commands in Dockerfile don't seem to be running
  • What's the difference between “docker start” and “docker restart”?
  • Docker build dockerfile
  • How to make Flask serve the right content types for static files on Alpine?
  • Passing Tomcat parameters to Docker
  • I’ve checked docker build -h and found no option related.

    How can I do this?

  • AWS ECS Error when running task: No Container Instances were found in your cluster
  • How do I create a database in the Postgres Docker container? [duplicate]
  • libcontainer - system programmers perspective
  • How does Docker share resources
  • Mount a volume in docker-compose. How is it done?
  • How run Docker's container with IIS in Ubuntu 16.04 LTS [closed]
  • 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.