Sobes.tech
Junior — Middle

What are the main instructions and components used when creating a Dockerfile?

sobes.tech AI

Answer from AI

Main instructions and components of a Dockerfile:

  • FROM — base image from which the new image is inherited.
  • RUN — execute commands in the container during build (e.g., installing packages).
  • COPY and ADD — copy files from the build context into the image.
  • CMD — command that runs when the container starts (can be overridden).
  • ENTRYPOINT — sets the main executable of the container.
  • WORKDIR — sets the working directory inside the container.
  • ENV — sets environment variables.
  • EXPOSE — declares ports that the container listens on.
  • VOLUME — declares mount points for data storage.

Example Dockerfile:

FROM openjdk:11
WORKDIR /app
COPY . /app
RUN ./gradlew build
EXPOSE 8080
CMD ["java", "-jar", "build/libs/app.jar"]