Junior — Middle
What components are included in creating a Docker image using a Dockerfile?
sobes.tech AI
Answer from AI
When creating a Docker image using a Dockerfile, the following main components are included:
- Base image (FROM) — the source image on which the new one is built, for example,
python:3.9. - Copying files (COPY or ADD) — adding source code, dependencies, and other resources into the image.
- Installing dependencies (RUN) — executing commands to install libraries, packages, and more, for example,
pip install. - Setting environment variables (ENV) — establishing environment variables.
- Defining the working directory (WORKDIR) — specifying the directory where commands will be executed.
- Startup command (CMD or ENTRYPOINT) — determines which command will run when the container starts.
Example 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"]