Django

Django & Docker

Dockerfile, docker-compose, multi-stage builds, volumes, networks, development vs production

20 면접 질문·
Senior
1

Which base image is recommended for a Django application in production?

답변

The python:3.x-slim image is recommended as it offers a balance between reduced size and compatibility. It contains essential libraries while avoiding unnecessary dependencies from full images. Alpine images, while lighter, can cause compatibility issues with some compiled Python libraries (like psycopg2).

2

What is the main advantage of a multi-stage build for a Django application?

답변

Multi-stage build significantly reduces the final image size by separating the build environment (with all compilation tools) from the runtime environment. Dependencies are compiled in the first stage, then only necessary files are copied to the final image, excluding build tools, temporary files and caches.

3

In a docker-compose.yml, how to ensure the Django container waits until PostgreSQL is ready to accept connections?

답변

The depends_on directive alone only guarantees container startup, not service availability. To wait until PostgreSQL is actually ready, use a wait-for-it.sh script, dockerize, or the service_healthy condition with a healthcheck. This approach prevents connection errors when the Django application starts.

4

What is the difference between COPY and ADD in a Dockerfile for a Django application?

5

How to optimize Docker layer caching when installing Python dependencies?

+17 면접 질문

다음 면접을 위해 Django을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기