Container
Container
A lightweight virtualization technology that packages an application and its dependencies. Docker is the best-known example. Provides a consistent execution environment.
Container
A lightweight virtualization technology that packages an application and its dependencies. Docker is the best-known example. Provides a consistent execution environment.
A container is a technology that bundles an application and all the dependencies required to run it (libraries, configuration files, binaries) into a single package and runs it in an isolated environment. Unlike a virtual machine, it shares the OS kernel, making it much lighter and faster.
Docker emerged in 2013 and popularized container technology. A container image is an immutable snapshot of an application and runs identically anywhere. It solves the "it works on my machine" problem.
Container runtimes include containerd and CRI-O, which are used through the standard interface (CRI) in Kubernetes. Docker Desktop is mainly used in development environments, while containerd is mainly used in production environments.
The image layer system stacks only the changes on top of a base image, enabling efficient storage and distribution. Multi-stage builds separate build dependencies from the runtime, so the final image size can be minimized.
# Dockerfile: 멀티스테이지 빌드 예시
# 빌드 스테이지
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
# 런타임 스테이지 (최소 이미지)
FROM node:20-alpine AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 appuser
COPY --from=builder --chown=appuser:nodejs /app/dist ./dist
COPY --from=builder --chown=appuser:nodejs /app/node_modules ./node_modules
USER appuser
EXPOSE 3000
ENV NODE_ENV=production
CMD ["node", "dist/index.js"]
---
# docker-compose.yml: 멀티 컨테이너 구성
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://db:5432/mydb
depends_on:
db:
condition: service_healthy
restart: unless-stopped
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: mydb
POSTGRES_USER: user
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user -d mydb"]
interval: 5s
timeout: 5s
retries: 5
volumes:
postgres_data:
DevOps: "Image build time is too long. Please reorder the Dockerfile so that layer caching can be used."
Development: "What order should I use?"
DevOps: "Put the things that change least often first. Copy package.json and run npm install, then copy the source code. If only the source changes, the npm install cache is used."
Interviewer: "Please explain the difference between a container and a virtual machine."
Candidate: "A VM runs a separate guest OS on top of a hypervisor, whereas containers share the host OS kernel. As a result, a container is tens of MB in size and starts in a few seconds, while a VM is several GB and takes several minutes. Containers provide process isolation, and VMs provide hardware isolation."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Reviewer: "The Dockerfile is running as root. For security, create a non-root user and run as that user."
Author: "I'll lower the privileges with the USER directive. I'll set a UID in the 1000 range."