I don’t understand how to write a Dockerfile to run Java HTTP

60 Views Asked by At

I need to write a dockerfile that clones a repository from github and starts a simple Java server. Аm i moving in the right direction? please help

FROM alpine/git
WORKDIR /app
RUN git clone https://github.com/trekawek/jhttp.git 

FROM maven:3.5-jdk-8-alpine
WORKDIR /app
COPY --from=0 /app/jhttp /app 
RUN mvn install 

FROM openjdk:8-jre-alpine
WORKDIR /app
COPY --from=1 /app/target/jhttp-0.0.1.jar /app 
CMD ["java -jar jhttp-0.0.1.jar"] 
1

There are 1 best solutions below

1
On

You are heading in the right direction in creating a Dockerfile that builds a Docker image. The image needs to contain all the dependencies your application requires, including Java itself.

I recommend reading Dockers official documentation on Dockerfile:

  1. Create a Dockerfile
  2. Dockerfile Reference
  3. Best practices for writing Dockerfiles

The above links should provide enough information on creating a Dockerfile.