Bird
Raised Fist0
Dockerdevops~20 mins

Using .dockerignore - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of a .dockerignore file in a Docker project?
easy
A. To specify environment variables for the Docker container
B. To tell Docker which files and folders to exclude when building an image
C. To configure network settings for Docker containers
D. To list all files that must be included in the Docker image

Solution

  1. Step 1: Understand the role of .dockerignore

    The .dockerignore file lists files and folders Docker should skip during image build.
  2. Step 2: Compare options with this role

    Only To tell Docker which files and folders to exclude when building an image correctly states that .dockerignore excludes files/folders from the build context.
  3. Final Answer:

    To tell Docker which files and folders to exclude when building an image -> Option B
  4. Quick Check:

    .dockerignore excludes files from build context [OK]
Hint: Think: .dockerignore tells Docker what NOT to include [OK]
Common Mistakes:
  • Confusing .dockerignore with Dockerfile
  • Thinking it lists files to include instead of exclude
  • Assuming it configures container runtime settings
2. Which of the following is the correct syntax to ignore the node_modules folder in a .dockerignore file?
easy
A. node_modules
B. node_modules/*
C. /node_modules/*
D. !node_modules

Solution

  1. Step 1: Review .dockerignore syntax for ignoring folders

    Simply writing the folder name like node_modules ignores it and all its contents.
  2. Step 2: Analyze options

    A (node_modules) is correct because it ignores the folder and its contents. B (node_modules/*) and C (/node_modules/*) ignore only contents, leaving an empty folder in the build context. D (!node_modules) negates ignoring, so it includes the folder.
  3. Final Answer:

    node_modules -> Option A
  4. Quick Check:

    Folder name alone ignores folder and contents [OK]
Hint: Write folder name alone to ignore it fully [OK]
Common Mistakes:
  • Using ! to ignore instead of include
  • Adding slashes inconsistently
  • Confusing .dockerignore with .gitignore syntax
3. Given this .dockerignore content:
node_modules
secret.txt
!secret.txt.bak

Which files will be included in the Docker build context?
medium
A. secret.txt and secret.txt.bak only
B. node_modules folder, secret.txt, secret.txt.bak
C. node_modules folder and secret.txt.bak only
D. secret.txt.bak only

Solution

  1. Step 1: Interpret the .dockerignore rules

    Lines exclude node_modules and secret.txt. The !secret.txt.bak line re-includes secret.txt.bak.
  2. Step 2: Determine included files

    Excluded: node_modules and secret.txt. Included: secret.txt.bak because of the ! rule.
  3. Final Answer:

    secret.txt.bak only -> Option D
  4. Quick Check:

    ! negates ignore = include secret.txt.bak [OK]
Hint: ! before filename re-includes it despite ignore [OK]
Common Mistakes:
  • Assuming ! negates all ignores
  • Including ignored folders by mistake
  • Ignoring the order of rules
4. You wrote this .dockerignore file:
node_modules
!node_modules/package.json

But package.json is still excluded from the build. What is the likely problem?
medium
A. Docker does not support negation (!) in .dockerignore
B. You must restart Docker daemon to apply .dockerignore changes
C. Negation does not work on files inside ignored folders
D. The syntax for negation is incorrect; use double exclamation marks (!!)

Solution

  1. Step 1: Understand negation behavior in .dockerignore

    Negation (!) cannot re-include files inside a folder that is ignored entirely.
  2. Step 2: Analyze the problem

    Since node_modules is ignored, negating node_modules/package.json does not include it back.
  3. Final Answer:

    Negation does not work on files inside ignored folders -> Option C
  4. Quick Check:

    Negation inside ignored folder fails [OK]
Hint: Negation can't rescue files inside ignored folders [OK]
Common Mistakes:
  • Thinking negation always works
  • Restarting Docker unnecessarily
  • Using wrong negation syntax
5. You want to speed up your Docker build by excluding all .log files except important.log in the root folder. Which .dockerignore content achieves this?
hard
A. *.log !important.log
B. *.log !important.log !important.log
C. *.log !important.log !important/*.log
D. *.log !important.log !important/

Solution

  1. Step 1: Write rule to ignore all .log files

    Using *.log ignores all files ending with .log anywhere.
  2. Step 2: Use negation to include only important.log in root

    !important.log re-includes that specific file in the root folder.
  3. Final Answer:

    *.log\n!important.log -> Option A
  4. Quick Check:

    Ignore all .log, then include important.log [OK]
Hint: Ignore *.log then negate important.log to include it [OK]
Common Mistakes:
  • Repeating negation lines unnecessarily
  • Negating folders instead of files
  • Using wrong paths for negation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard