hardMultiple ChoiceObjective-mapped
XK0-006 Practice Question: A container needs to communicate with a database…
A container needs to communicate with a database on the host machine using the default bridge network. The container cannot resolve the host by hostname. Which approach should be used?
⚠ Common exam trap
Test-takers frequently confuse `--net=host` as a quick fix for hostname resolution, not realizing it sacrifices network isolation and is not the intended method for reaching the host from a container on the default bridge.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use --add-host host.docker.internal:host-gateway
`--add-host host.docker.internal:host-gateway` adds a special entry to the container's `/etc/hosts` file that resolves `host.docker.internal` to the host machine's gateway IP address, which on the default bridge network is the host itself. This allows the container to reach the host by a consistent hostname without relying on Docker's internal DNS, which does not resolve hostnames on the default bridge. The `host-gateway` magic value automatically maps to the host's IP (typically 172.17.0.1 on Linux).
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Set --net=host
Why it's wrong here
Using host network mode reduces container isolation and is not recommended for security.
- ✗
Use --link db:db
Why it's wrong here
The --link flag is a legacy feature and deprecated; it also does not resolve the host itself.
- ✗
Create a custom bridge network
Why it's wrong here
A custom bridge network provides DNS resolution between containers but does not automatically resolve the host.
- ✓
Use --add-host host.docker.internal:host-gateway
Why this is correct
This adds a host entry that resolves to the host's IP via the gateway, allowing the container to reach host services.
Visual reference
Go deeper
Related to this question
Learn chapter
Linux Fundamentals and History
Key term
Linux
Linux is an open-source operating system that manages computer hardware and software, widely used in servers, desktops, and embedded systems.
Key term
Value
Value is the perceived worth, benefit, or usefulness that a service, product, or activity delivers to stakeholders, especially customers and the business.
About these practice questions
This XK0-006 question is part of Courseiva's 979-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.