Sobes.tech
Junior — Middle

How is the setup and configuration of Docker containers carried out?

sobes.tech AI

Answer from AI

Configuration and setup of Docker containers are usually done using Dockerfile and docker-compose.yaml.

  • Dockerfile — a text file with instructions for building an image. It specifies the base image, copies files, installs dependencies, and sets startup commands.

Example Dockerfile for a Python application:

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
  • docker-compose.yaml — a file for describing and running multiple containers with network settings, volumes, and environment variables.

Example docker-compose.yaml:

version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"
    environment:
      - DEBUG=1

You can also set environment variables, mount data volumes, configure networks, and resource limits.

Thus, configuration allows defining how the container will operate, what dependencies are needed, and how it interacts with other services.