Whenever a “docker builds
” command is executed we see a line that tells uploading context. This refers to the creation of a .tar
file by including all files in the directory where the Dockerfile is present and uploading them to docker daemon. Consider if we are putting Dockerfile in home directory entire files in your home and in all subdirectories would be included in the creation of a .tar
file. Thus before updating the context docker daemon checks for the .dockerignore
file. All files that match the data in the .dockerignore file would be neglected. Hence sensitive information is not sent to the Docker daemon.
sample .dockerignore
file looks like this :
# comment
*/temp*
*/*/temp*
Temp?
This .dockerignore
file ignores all files and directories whose names start with temp in any immediate subdirectory of the root or from any subdirectory that is two levels below the root. It also excludes files and directories in the root directory whose names are a one-character extension of temp. Everything that starts with # is ignored.