What is a Dockerfile?
A Dockerfile is a text file with a set of instructions that describe how to build a Docker image. Each line in a Dockerfile is a build step (installing dependencies, copying files, running commands, etc.).
What a Dockerfile does
- sets the base image (for example,
ubuntuorpython:3.10); - copies project files into the future image;
- installs dependencies;
- configures the working directory and environment variables;
- specifies the command that will run when the container starts.
The simplest example of a Dockerfile
Dockerfile
FROM python:3.10
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]How it is used
- Write the Dockerfile
- Build the image:
bash
docker build -t myapp .- Run the container:
bash
docker run myappIn short: a Dockerfile is the recipe. A Docker image is the finished dish. A container is a running instance of that "dish" in action.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.