Home > database >  Issues with ignoring docker context using .dockerignore
Issues with ignoring docker context using .dockerignore

Time:10-19

 .
├── A
└── B
    ├── .dockerignore
    ├── Dockerfile
    └── run_script.sh

My folder structure looks similar to the above tree. I have a Dockerfile, and a .dockerignore file. I use the run-script to build my docker image. In the build, i send the entire context from the root. So, effectively, the context contains both the folders A, and B.

The run script contains the following command:

docker build docker build  -f  Dockerfile ..

In the .dockerignore file, I would like to ignore certain files which are inside the folder A. In the dockerignore documents, I can use */ or **/ basically to ignore subdirectories, but using them here does not seem to be effective in ignoring the files (As they are located in the parent/root directory)

These below commands do not help

 **/A
*/A

I tried having the .dockerignore file in the root (i.e root contains the folders A, B and .dockerignore -This works). The ignore file contains:

A/
B/

So my question is if there is a solution of ignoring files and folders which are present in the build context, but are technically a level above the stored .dockerignore?

CodePudding user response:

The .dockerignore file has to be placed in the context directory (in your case the folder that contains both A and B).

This is specified in the docs:

To increase the build’s performance, exclude files and directories by adding a .dockerignore file to the context directory.

Also here

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.

CodePudding user response:

I haven't tested this, but can you try to just use:

../A

.. is a reference to the parent directory.

  • Related