Interview Q&A / Docker & Kubernetes
Docker & Kubernetes interview questions
Images, containers, Dockerfiles, pods and deployments, from first principles.
Prefer rapid revision? Practise Docker & Kubernetes short interview answers →
- Does EXPOSE in a Dockerfile make a port reachable from outside?
No. EXPOSE is only documentation of the port the app listens on. To make it reachable from the host you must publish it with -p, or -P to publish all exposed ports to random host ports.
BeginnerQuick answer1 min read - How can two Docker containers talk to each other?
Put them on the same user-defined network and call one from the other using its container or service name and the container port. Publishing a port with -p is only needed for access from the host.
BeginnerQuick answer1 min read - What are the bridge, host and none network modes in Docker?
bridge (default) gives a container its own network and IP behind a virtual switch, host shares the host's network stack with no isolation, and none disables networking except loopback.
BeginnerQuick answer1 min read - What are the different Service types in Kubernetes?
ClusterIP exposes a Service only inside the cluster, NodePort opens a port on every node, LoadBalancer provisions a cloud load balancer, and ExternalName maps the Service to an external DNS name.
BeginnerQuick answer1 min read - What is an Ingress in Kubernetes and how does it differ from a LoadBalancer Service?
An Ingress defines HTTP and HTTPS routing rules by host and path, handled by an Ingress controller. One load balancer can serve many services, while a LoadBalancer Service creates one external load balancer per Service.
BeginnerQuick answer1 min read - How do you publish a container port only on localhost, not to the whole network?
Bind the host side to the loopback address: docker run -p 127.0.0.1:8080:80. By default -p 8080:80 listens on all interfaces, so anyone on your network can reach it.
IntermediateQuick answer1 min read - Why does localhost inside a container not reach a database running on your laptop?
Inside a container, localhost means the container itself, not the host. To reach a host service use host.docker.internal (Docker Desktop, or with --add-host on Linux), or put both on a Docker network and use the service name.
IntermediateQuick answer1 min read - Why should you create a user-defined bridge network instead of using the default one?
On a user-defined bridge, containers resolve each other by name through Docker's built-in DNS, and you get better isolation. On the default bridge you must use IP addresses or legacy links.
IntermediateQuick answer1 min read