liveBook · Manning

Entrypoint instruction

As explained in Learn Docker in a Month of Lunches, Second Edition

The ENTRYPOINT instruction specifies the executable or command that a container runs when started from an image.

ENTRYPOINT defines what Docker runs when a container starts from an image. Use it to make the image launch a specific application, such as a Java program packaged in a JAR. section 4.2

Listing 4.2 Dockerfile for building a Java app with Maven
FROM diamol/maven:2e AS builder

WORKDIR /usr/src/iotd
COPY pom.xml .
RUN mvn -B dependency:go-offline

COPY . .
RUN mvn package

# app
FROM diamol/openjdk:2e

WORKDIR /app
COPY --from=builder /usr/src/iotd/target/iotd-service-0.1.0.jar .

EXPOSE 80
ENTRYPOINT ["java", "-jar", "/app/iotd-service-0.1.0.jar"]

See a complete Dockerfile that copies a compiled JAR into a runtime image and starts it with ENTRYPOINT. section 4.2

Start a Java application

ENTRYPOINT ["java", "-jar", "/app/iotd-service-0.1.0.jar"] After building the image, run it with `docker container run --name iotd -d -p 800:80 --network nat image-of-the-day`. Docker starts Java with the application JAR, while the image exposes port 80. section 4.2

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains the startup role and shows executable, arguments, and JAR path, while treating CMD only as an alternative.
Examples
Uses a Java Dockerfile and a docker container run command to launch a REST API from a packaged JAR.
What it assumes
Assumes Dockerfile, image, container, Java runtime, and packaged JAR concepts.
What you can do after
Operate/configure a Docker image to launch a Java application automatically when its container starts.
How it connects
Connects ENTRYPOINT with CMD, Docker images, containers, Java, JAR files, and exposed ports.

Also explained in

Compare how 3 books explain entrypoint instruction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.