Junior — Middle
Can you explain what a Dockerfile is and how it is used to create containers?
sobes.tech AI
Answer from AI
A Dockerfile is a text file containing a set of instructions that describe how to build a Docker image. It includes a sequence of commands that Docker executes to create a container image.
Main points:
- The Dockerfile specifies the base image, copying files, installing dependencies, running commands, and configuring the environment.
- Using the Dockerfile, the
docker buildcommand creates an image that can be run as a container.
Example of a simple Dockerfile for a Java application:
FROM openjdk:11
COPY ./app.jar /app/app.jar
CMD ["java", "-jar", "/app/app.jar"]
This file uses the OpenJDK 11 base image, copies the application file into the container, and sets the command to run the application.