Ignoring Files and Folder During Docker Build

What is Use of DockerIgnoreFile

This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using ADD or COPY.

1)Ignore a file

2)Ignore a Folder and SubFolder

You Can Ignore below things

How to Ignore

Create a .dockerignore file in Root Dir of Project

How .DockerIgnnore File work

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. 

If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it. 

This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using ADD or COPY.
Docker CLI will only look for .dockerignore file in the root directory of the context, if you have a monorepo of multiple packages, make sure .Dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.

lets do Demo

Thank you

Ignoring Files and Folder During Docker Build

By Sagar Mal Shankhala

Ignoring Files and Folder During Docker Build

  • 237