Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issues with ignoring docker context using .dockerignore

 .
├── 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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading