Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple .dockerignore files in same directory

Tags:

docker

In the same directory I have two Dockerfiles and I would like to add a separate .dockerignore for each of them.

Currently, I have:

Dockerfile.npm
Dockerfile.nginx

But can I have something like this?:

.dockerignore.npm
.dockerignore.nginx
like image 355
Luminance Avatar asked Jul 27 '17 07:07

Luminance


2 Answers

I don't think you can specify a different ignore file while doing a build. But since you are creating a separate file, you can write a shell script

build_nginx.sh

#!/bin/bash
ln -fs .dockerignore.nginx .dockerignore
docker build -f Dockerfile.nginx -t nginxbuild .

build_npm.sh

#!/bin/bash
ln -fs .dockerignore.npm .dockerignore
docker build -f Dockerfile.npm -t npmbuild .

If you need to use it with docker-compose then you need to separate folders for ngixn and npm and then can have their individual .dockerignore file. In your docker-compose.yml file you need specify the name of the directory as the context

like image 184
Tarun Lalwani Avatar answered Sep 22 '22 13:09

Tarun Lalwani


Multiple dockerignore files or specifying which dockerignore file to use is currently not supported by Docker.

See this issue on Github: Add support for specifying .dockerignore file with -i/--ignore

like image 39
Blaise Avatar answered Sep 18 '22 13:09

Blaise