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 check a container's IP address, environment variables and resource usage?

    docker inspect shows full JSON details such as IP, env vars, mounts and state, and -f with a Go template pulls out one field. docker stats shows live CPU, memory and network usage.

    BeginnerQuick answer1 min read
  2. How do you find out why a Docker container exited immediately?

    Run docker ps -a to see its status and exit code, then docker logs for the output. A container lives only as long as its main process, so a quick exit means the process finished or crashed.

    BeginnerQuick answer1 min read
  3. How do you view and follow the logs of a running container?

    Use docker logs <container>. Add -f to follow new lines, --tail N to show only the last N lines, and --since to limit by time. It shows whatever the main process wrote to stdout and stderr.

    BeginnerQuick answer1 min read
  4. What does docker run -d -p 8080:80 --name web nginx do?

    It starts a container named web from the nginx image in the background (-d) and publishes container port 80 on host port 8080, so http://localhost:8080 reaches nginx.

    BeginnerQuick answer1 min read
  5. What happens when you run docker run nginx and the image is not on your machine?

    Docker looks locally, does not find nginx:latest, pulls it from Docker Hub, then creates and starts the container. With no tag given it uses latest, which is just a default tag name, not a guarantee of the newest version.

    BeginnerQuick answer1 min read
  6. What is the difference between docker compose stop, down and down -v?

    stop halts containers but keeps them. down stops and removes containers and networks. down -v also deletes the named volumes, which destroys stored data.

    BeginnerQuick answer1 min read
  7. What is the difference between docker exec and docker attach?

    docker exec starts a new process inside a running container, such as a shell. docker attach connects your terminal to the container's existing main process, so exiting it can stop the container.

    BeginnerQuick answer1 min read
  8. What is the difference between docker rm, docker rmi and docker system prune?

    docker rm deletes containers, docker rmi deletes images, and docker system prune bulk-removes stopped containers, unused networks and dangling images. Add -a for all unused images, and --volumes for unused volumes.

    BeginnerQuick answer1 min read
  9. What is the difference between docker stop and docker kill?

    docker stop sends SIGTERM so the app can shut down cleanly, then SIGKILL after a 10 second grace period. docker kill sends SIGKILL (or a signal you choose) straight away, with no chance to clean up.

    BeginnerQuick answer1 min read
  10. What is the difference between docker compose up and docker compose run?

    up creates and starts all services (or those named) as defined, with ports and dependencies. run starts a one-off container for a single service with a command you give, then exits, and does not publish ports by default.

    IntermediateQuick answer1 min read