Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Dockerfile example to extract the application jar based on an argument #18932

Closed

Conversation

glours
Copy link
Contributor

@glours glours commented Nov 7, 2019

Add stage build to unpack jar
Change runtime base image by a jre-alpine

@pivotal-issuemaster
Copy link

@glours Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@glours Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 7, 2019
@philwebb philwebb added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 7, 2019
@philwebb philwebb added this to the 2.2.x milestone Nov 7, 2019
@glours glours force-pushed the update_dockerfile_deployment branch from d15fba6 to f1d6492 Compare November 7, 2019 23:26
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I understand that part of this PR is to show how docker could take care of extracting the fat jar in such a way that its content can be layered in the image. I think this makes the example less generic as described further in a comment below. Thoughts?

ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.MyApplication"]
FROM openjdk:8-jdk-alpine AS builder
WORKDIR target/dependency
COPY ./target/*.jar .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be more than one jar in this directory. The regular build and the fat jar output. A build may also have other classified artifacts and we can't really know in advance which one is going to be the fatjar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I was focused on the user flow experience, and try to resolve the forgetting of unzip the jar, got your point maybe I should remove this section

Copy link
Contributor Author

@glours glours Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we can use a build arg with the name of the fatjar & add a command example for the docker build, wdyt?
ex:
docker build --build-arg fatjar=my-fat-jar-version-1.0.0
&

FROM openjdk:8-jdk-alpine AS builder
WORKDIR target/dependency
ARG fatjar
COPY ./target/${fatjar}.jar
RUN jar -xf ./${fatjar}.jar

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target is a usual location for Maven but I like the idea of the argument. Can we improve this so that we give the (full) path to the fat jar and then it does everything else without assuming a directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes of course, I'll update in that way 😉

RUN jar -xf ./*.jar

FROM openjdk:8-jre-alpine
EXPOSE 8080
Copy link
Member

@snicoll snicoll Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really a Docker expert but I don't understand why hardcoding 8080 here is something we should do. This might not be a webapp. It might be a webapp running on a different port.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, not need at all.
It's some rest of local testing, sorry 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way the main point here was to use a jre instead of a jdk alpine image

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Nov 8, 2019
@glours glours force-pushed the update_dockerfile_deployment branch from f1d6492 to 2f427e7 Compare November 8, 2019 12:20
Add stage build to unpack jar
Change runtime base image by a jre-alpine

Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
@glours glours force-pushed the update_dockerfile_deployment branch from 2f427e7 to 6acd83e Compare November 8, 2019 13:26
@snicoll snicoll removed the status: waiting-for-feedback We need additional information before we can continue label Nov 12, 2019
@glours
Copy link
Contributor Author

glours commented Nov 13, 2019

Hi @snicoll
I saw you added the label waiting-for-feedback few hours ago, did I miss something?
I changed code regarding your comments last friday, is it fine for you now?

@snicoll
Copy link
Member

snicoll commented Nov 13, 2019

I actually removed it as you’ve addressed it. Thanks!

@snicoll snicoll self-assigned this Nov 13, 2019
@snicoll snicoll changed the title Improve Dockerfile example in deployment documentation Improve Dockerfile example to extract the application jar based on an argument Nov 13, 2019
snicoll pushed a commit that referenced this pull request Nov 13, 2019
snicoll added a commit that referenced this pull request Nov 13, 2019
@snicoll snicoll closed this in 7d54054 Nov 13, 2019
@snicoll
Copy link
Member

snicoll commented Nov 13, 2019

Thank you for making your first contribution to Spring Boot.

@snicoll snicoll modified the milestones: 2.2.x, 2.2.2 Nov 13, 2019
mathieufortin01 pushed a commit to mathieufortin01/spring-boot that referenced this pull request Nov 15, 2019
mathieufortin01 pushed a commit to mathieufortin01/spring-boot that referenced this pull request Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants