0
0
Dockerdevops~20 mins

Using .dockerignore - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dockerignore Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Effect of .dockerignore on Docker build context size

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?

AAll files including .log files and temp directory files
BAll files except those ending with .log and all files inside the temp directory
COnly files ending with .log and files inside temp directory
DOnly files outside the project folder
Attempts:
2 left
💡 Hint

Think about what *.log and temp/ patterns exclude.

🧠 Conceptual
intermediate
1:00remaining
Purpose of .dockerignore in Docker builds

Why is it important to use a .dockerignore file in your Docker project?

ATo define the order of Dockerfile instructions
BTo specify which Docker images to pull before building
CTo list environment variables for the container
DTo reduce the size of the build context sent to the Docker daemon, speeding up builds and avoiding unnecessary files
Attempts:
2 left
💡 Hint

Think about what happens when Docker sends files to build the image.

Troubleshoot
advanced
1:30remaining
Why is a large file still included despite .dockerignore?

You added secret.txt to your .dockerignore file, but it still appears in the Docker image after build. What is the most likely reason?

AThe <code>secret.txt</code> file was copied in a previous build layer and cached, so the cache must be cleared
BDocker does not support ignoring individual files
CThe <code>.dockerignore</code> file must be named <code>dockerignore.txt</code>
DThe Dockerfile must include <code>IGNORE secret.txt</code> instruction
Attempts:
2 left
💡 Hint

Think about Docker build cache and layers.

Best Practice
advanced
2:00remaining
Best practice for .dockerignore patterns

Which of the following .dockerignore patterns correctly excludes all files in the node_modules folder and any .env files anywhere in the project?

A
node_modules
.env
B
node_modules/
**/.env
C
/node_modules
.env
D
node_modules/*
.env/*
Attempts:
2 left
💡 Hint

Remember that / at the end means folder, and **/ matches files anywhere.

🔀 Workflow
expert
2:30remaining
Order of operations when building with .dockerignore

Put these steps in the correct order when building a Docker image with a .dockerignore file:

A4,1,2,3
B1,4,2,3
C4,2,1,3
D1,2,4,3
Attempts:
2 left
💡 Hint

Think about what happens first when you run docker build.