Interview Q&A / Docker & Kubernetes

INTERVIEW Q&A · 67 QUESTIONS

Docker & Kubernetes interview questions

Images, containers, Dockerfiles, pods and deployments, from first principles.

  1. 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
  2. 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
  3. 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