Middle
How to create a Docker image? What is a Dockerfile and the docker build command?
sobes.tech AI
Answer from AI
A Docker image is a template from which a container is created. To create a Docker image, you need to write a Dockerfile — a text file with instructions describing how to build the image: base image, copying files, installing dependencies, running commands, etc.
The docker build command reads the Dockerfile and sequentially executes the instructions, creating the image layer by layer. The result is a ready-to-run container image.
Example of a simple Dockerfile:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . ./
CMD ["python", "app.py"]
Building the image:
docker build -t my-python-app .