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 commented Nov 7, 2019

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

@pivotal-issuemaster

This comment has been minimized.

Copy link

pivotal-issuemaster commented Nov 7, 2019

@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

This comment has been minimized.

Copy link

pivotal-issuemaster commented Nov 7, 2019

@glours Thank you for signing the Contributor License Agreement!

@philwebb philwebb added this to the 2.2.x milestone Nov 7, 2019
@glours glours force-pushed the glours:update_dockerfile_deployment branch from d15fba6 to f1d6492 Nov 7, 2019
Copy link
Member

snicoll left a comment

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 .

This comment has been minimized.

Copy link
@snicoll

snicoll Nov 8, 2019

Member

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.

This comment has been minimized.

Copy link
@glours

glours Nov 8, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@glours

glours Nov 8, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@snicoll

snicoll Nov 8, 2019

Member

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?

This comment has been minimized.

Copy link
@glours

glours Nov 8, 2019

Author Contributor

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

RUN jar -xf ./*.jar
FROM openjdk:8-jre-alpine
EXPOSE 8080

This comment has been minimized.

Copy link
@snicoll

snicoll Nov 8, 2019

Member

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.

This comment has been minimized.

Copy link
@glours

glours Nov 8, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@glours

glours Nov 8, 2019

Author Contributor

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

@glours glours force-pushed the glours:update_dockerfile_deployment branch from f1d6492 to 2f427e7 Nov 8, 2019
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 glours:update_dockerfile_deployment branch from 2f427e7 to 6acd83e Nov 8, 2019
@glours

This comment has been minimized.

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

This comment has been minimized.

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 added 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

This comment has been minimized.

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 added a commit to mathieufortin01/spring-boot that referenced this pull request Nov 15, 2019
mathieufortin01 added 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.