简体   繁体   中英

How to dockerizing a spring boot app with one Dockerfile?

From the official guide , we can build a docker image by maven or gradle. It saying we need a Dockerfile and then run the maven or gradle command to generate a runable docker image:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

But in my use case is that the cloud vendor requires that we just supplying one Dockerfile and they will build an Docker image from my code base based on the supplied Dockerfile. And there is no chance to run my own build script. So how can I handle this situation? Is there way to build a runable docker image from just a Dockerfile?

Use the RUN command inside your Dockerfile to perform any action at build time. Eg:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
RUN echo "something" && \
  echo "then print this" && \
  echo "and so on.. any shell command can be performed here"
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Avoid multiple RUN commands. A new overlay layer is created for each one, which increases the size of your final image.

It's good to know how an image is created to understand. When you do docker build . , your docker client will copy everything that is in the directory of your Dockerfile to the docker host. Then docker creates a container from the FROM instruction, and simply follows the instructions in the Dockerfile to modify that container. Once the instructions are completed, docker creates an image from the state of that temporary container and discards the container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM