Junior — Middle
Can you list the main steps for creating a Dockerfile?
sobes.tech AI
Answer from AI
Main steps for creating a Dockerfile:
- Choose a base image — specify which image your container will inherit from, for example,
python:3.9. - Copy files — use the
COPYcommand to transfer necessary files and directories into the container. - Install dependencies — use
RUNto install required packages, for example,pip install -r requirements.txt. - Set the working directory — use
WORKDIRto define the directory inside the container. - Define the startup command — use
CMDorENTRYPOINTto specify the command that will run when the container starts.
Example of a simple Dockerfile for a Python application:
FROM python:3.9
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]