mon
mon

Reputation: 22254

Where to place .dockerignore for docker build -f <path/to/docker/Dockerfile>

When running docker build in the directory /X and the Dockerfile exist in /X/path/to/docker/Dockerfile, where should I place .dockerignore?

Is it /X/path/to/docker/.dockerignore or /X/.dockerignore.

.dockerignore file tells below but what exactly the root directory of the context is not clearly defined there.

Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context.

Upvotes: 14

Views: 6511

Answers (1)

tplusk
tplusk

Reputation: 1007

The root directory of the context means the root of where you are building from, typically the directory you are running the docker command. It is the usually the last argument to docker commands. So say you are in /X/, when you end a command like docker build -f path/to/docker/Dockerfile ., the last . is the context (current directory), and your docker file should be in /X/.dockerignore. Instead let's say you ran like docker build -f path/to/docker/Dockerfile path/to/docker/Dockerfile, it would be in /X/path/to/docker/.dockerignore.

Another alternative, I believe, is if you add a file /X/path/to/docker/Dockerfile.dockerignore, it will be honored no matter what your build context is.

Upvotes: 7

Related Questions