Junior — Middle
Какова роль инструкции FROM в Dockerfile и зачем она необходима?
sobes.tech AI
Answer from AI
The FROM instruction in a Dockerfile specifies the base image from which a new image will be built. It is a mandatory directive that defines the starting point for building the container.
Role of FROM:
- Defines the operating system or environment on which your container will run (e.g.,
ubuntu,alpine,openjdk). - Allows the use of pre-built images with installed software, which speeds up and simplifies the build process.
- Multiple
FROMinstructions can be used in a single Dockerfile to create multi-stage builds.
Example:
FROM openjdk:11
COPY . /app
WORKDIR /app
RUN ./gradlew build
CMD ["java", "-jar", "build/libs/app.jar"]
Here, FROM openjdk:11 sets the base image with JDK 11 installed.