Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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.

I've checked docker build -h and found no option related.

How can I do this?

like image 919
satoru Avatar asked Dec 01 '16 07:12

satoru


People also ask

Where is .dockerignore file located?

dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.

How do I override Dockerignore?

Change App Structure. The only other useful option I can think of is to split out your ADD or COPY into multiple commands so that you don't rely on the the . dockerignore to filter files to the other 3 images. This would probably require your assets directory to be stored outside of your application root.

Does Docker Compose use Dockerignore?

Yes, the Dockerfile , docker-compose. yml , and . dockerignore are all used to build the image and spin up a container, however, that's where the purpose of these files stop.


1 Answers

Docker 19.03 shipped a solution for this.

The Docker client tries to load <dockerfile-name>.dockerignore first and then falls back to .dockerignore if it can't be found. So docker build -f Dockerfile.foo . first tries to load Dockerfile.foo.dockerignore.

Setting the DOCKER_BUILDKIT=1 environment variable is currently required to use this feature. This flag can be used with docker compose since 1.25.0-rc3 by also specifying COMPOSE_DOCKER_CLI_BUILD=1.

See also:

  • https://github.com/moby/moby/issues/12886#issuecomment-480575928
  • https://github.com/moby/moby/issues/12886#issuecomment-518843764
  • https://github.com/moby/moby/issues/12886#issuecomment-523706042
like image 85
thisismydesign Avatar answered Oct 03 '22 23:10

thisismydesign