You have a project folder with 100 files. Your .dockerignore file contains *.log and temp/. Which files will NOT be sent to the Docker daemon during docker build?
Think about what *.log and temp/ patterns exclude.
The .dockerignore file excludes files matching its patterns from the build context. Here, files ending with .log and everything inside the temp folder are excluded and not sent to Docker daemon.
Why is it important to use a .dockerignore file in your Docker project?
Think about what happens when Docker sends files to build the image.
The .dockerignore file tells Docker which files to ignore when sending the build context. This reduces build time and avoids including sensitive or unnecessary files.
You added secret.txt to your .dockerignore file, but it still appears in the Docker image after build. What is the most likely reason?
Think about Docker build cache and layers.
If a file was included in a previous build layer, Docker may reuse that cached layer. Even if .dockerignore excludes it now, the cache can cause the file to appear. Clearing the cache or forcing a rebuild fixes this.
Which of the following .dockerignore patterns correctly excludes all files in the node_modules folder and any .env files anywhere in the project?
Remember that / at the end means folder, and **/ matches files anywhere.
node_modules/ excludes the entire folder and its contents. **/.env matches any .env file in any subfolder. Other options either miss the folder or do not match files correctly.
Put these steps in the correct order when building a Docker image with a .dockerignore file:
Think about what happens first when you run docker build.
First, the Docker client starts the build (4). Then it reads .dockerignore to exclude files (1). Next, it sends the filtered context to the daemon (2). Finally, the daemon runs the Dockerfile instructions (3).