docker has to start java/undertow application during build phase and it should be available during run phase. however container changes related to starting of java server are not persisted after java process got launched.
So changes done during this step makes no impact on image.
The last command in my docker file is
RUN java -jar /svc/app/svc-0.0.1-SNAPSHOT.jar $2>server.log & sleep 5
when I run this container I can see that output exists in the server.log file confirming server successfully started
StartServices - Services Started
But when I run the container there is no service running. I can start it manually but it is not how I want to do it. I want my server been up when container is up.
Notice
& sleep 5
If I do not wait for these 5 seconds it will be no any log created. Docker would abandon this step immediately without letting my java application to start.
However even "sleep 5" let my application to start, docker still ignores changes in the image and do not apply them.
So when I do "docker run" my application is not running.
here is Dockerfile :
FROM anapsix/alpine-java
ENV TC_BASE=/opt/tc_base
ENV APP_BASE=$TC_BASE/svc
ENV PATH=.:$PATH
RUN apk update && apk add unzip
COPY files/build/lib/svc/target/svc-0.0.1-SNAPSHOT-bin.zip $APP_BASE/
COPY files/build/lib/api/src/main/resources/api.properties $TC_BASE/conf/api/
COPY files/build/lib/svc/src/main/resources/svc.properties $TC_BASE/conf/svc/
COPY files/build/lib/svc/src/main/resources/logback.xml $TC_BASE/conf/svc/
RUN cd $APP_BASE ; unzip -q svc-0.0.1-SNAPSHOT-bin.zip ; rm svc-0.0.1-SNAPSHOT-bin.zip ; mv svc-0.0.1-SNAPSHOT/* . ; rm -rf svc-0.0.1-SNAPSHOT
EXPOSE 7009
RUN java -jar $TC_BASE/svc/app/svc-0.0.1-SNAPSHOT.jar $2>server.log & sleep 5
Well, it should be ENTRYPOINT not RUN. Entrypoint is invoked when container starts and it is what I need. RUN is executed during build time however it only affects filesystem. Docker image does not contain execution state of application, so when image is created it does not have information about application that have been started. In order to start applications they have to be set as ENTRYPOINT
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.