Why do backend teams package services with Docker, and what makes a good Dockerfile?
What the interviewer wants to hear
- Same environment in development, CI and production
- Images bundle the app and its dependencies; containers are isolated processes
- Small base images and multi-stage builds
- Order layers for caching and use a .dockerignore
- Run as a non-root user and keep secrets out of the image
Model answer
Docker packages the app with its runtime and dependencies into an image, so the same artifact runs the same way on a laptop, in CI and in production. That removes "works on my machine" problems and makes deployments and rollbacks simple, because you just run a different image tag. It also lets developers start dependencies like PostgreSQL and Redis with one compose file. A good Dockerfile uses a small, pinned base image, and a multi-stage build so build tools do not end up in the final image. I copy the dependency manifests first and install them before copying the source, so that layer stays cached. I add a .dockerignore to skip node_modules and .git. Finally I run the process as a non-root user and pass secrets and configuration through environment variables or a secret manager at runtime, never baking them into the image.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Backend Developer questions
- How would you design a REST API for a simple blog with posts and comments? Mention URLs, methods and status codes.
- When would you choose a SQL database and when a NoSQL database?
- What is the difference between authentication and authorization? How would you implement both in an API?
- Explain what happens on the backend from the moment a request hits your server until a response is sent.
- What is a database index, and what are its costs? How do you decide which columns to index?
- What is a database transaction, and what do the letters in ACID mean? Give an example where you need one.
- What are logs, metrics and traces, and how would you use each one to run a backend service?
- How would you test a new POST /orders endpoint? Which kinds of tests would you write?
- Explain the HTTP status code classes and give examples of codes a REST API commonly returns.