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.

  • Vagrant Docker Nginx Resolving slow
  • AWT error while trying to build Jenkins Docker image based on Alpine -
  • Use Dokku Environment variables in DockerFile
  • How to run gerrit cookbook inside docker containers?
  • Deploying a minimal flask app in docker - server connection issues
  • Setting insecure registry in docker-in-docker image docker daemon
  • I’ve checked docker build -h and found no option related.

    How can I do this?

  • Shipping multi-container Docker app
  • Docker - Rstudio - R old version running together
  • How to run Swagger Spring Application using Jetty on Docker
  • Problems running scala/play project with Docker
  • How to develop Rails app running inside Docker
  • Creating proper build or deployment chain with Microservices, Docker, Jenkins and GIT
  • 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.