How do I restart a container with a new spring-boot JAR?

Hi,
please help me.

With the upgrade of the docker, adding jar to the container with the absolute path no longer works. How to make, that at restart of the container the new jar was picked up?
I did a new jar and restarted the container, now I can not do this because it’s impossible to specify the absolute path to the new jar in Dockerfile?

Here is my Dockerfile that worked before updating to the new version of the docker. From him I created a image without any problems.

FROM java:8

VOLUME /tmp
EXPOSE 8888
ADD /home/jdev/docker-storage/jenkins/workspace/CA/build/libs/ca.jar /app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Now I can not create an image, because I need to specify a relative path. And after restart a new image is not copied to the Docker-container.

ADD /home/jdev/docker-storage/jenkins/workspace/CA/build/libs/ca.jar /app.jar

Thanks for the help!

1 Like

wrap the docker build in a script… copy the jar file here, then add it, then remove it…
or create a local link to the jar…

You would not be able to tell how to create a local link to the jar?
Do you mean volume in Dockerfile?

Thanks.

ADD has always required an relative path; and it will try to unpack archive files, which you probably don’t want here. Copy the artifact to the directory the Dockerfile is in and COPY with a relative path.

There are a couple of other things in the Dockerfile that are unnecessary, will have odd side effects, or will make your container harder to debug. I’d write something a little more like:

FROM openjdk:8
COPY ca.jar /app.jar
CMD ["java", "-Djava.security.egd=file:/dev/urandom","-jar","/app.jar"]

If it’s still not working, two good things to try are looking at the output of the container (don’t start it with docker run -d if it exits immediately), and starting it with a shell (docker run --rm -it image name /bin/sh) and looking around.

Thanks for the answer. I understand what you mean. I do not understand what happens with the container when the restart command is called. Where does the docker service know where the docker file is located?

the container, like the images, are in the local host registry.

docker ps -a lists all containers
docker images lists all images (which have also have containers using them)

this is just a build time process, you copy the jar from the absolute folder to the current folder, then the
dockerfile ADD command uses the instance in the local folder and puts it whereever u want in the image.

Thank you, I understood this. I do not understand where the docker-service knows where to look for the jar file when it makes container restart. After all, we point the way only when we create an image.

i think you need to create another image and start that, rather than try to import another jar file.

otherwise u have t use volume to mount a local folder in the container, and copy the jar at run time…

Tell me please how? I do not want to create a new image every time after deploy. It’s too long.

use -v on the docker run, to map a local folder to a container folder
for example (make the source folder read only too)

  -v .:/foo:ro

put the jar file in the current directory, and then in the CMD in the dockerfile, copy the jar to the place inside the container u want it. then start the command that uses the jar file.

i believe when u do docker start (actually is a restart), then the container will do the same CMD process.
least it used to.

I know this, I just thought that you need to specify everything in the dockerfile. I think everything will turn out. Thank you!

no… just whatever u need.

i have a 50 line script that runs when my container starts (or restarts)
it unbundles a big directory tree (it would make the container >1.5gb in size if packaged with the container)
then checks other folders to copy in supporting jar files and reqired license files, then determines which command to execute based on the parms passed. so the one tiny container can be any of 10 different personalities.

the software it runs is in the zip/gz… the rest of the image is personality agnostic.

I’m doing something wrong. My ca.jar in /home/jdev/test/ca.jar
Dockerfile:

FROM java:8

VOLUME /tmp
EXPOSE 8888
RUN bash -c 'touch /tmp/app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/urandom","-jar","/tmp/app.jar"]

and console

jdev@vmd23690:~$ sudo docker build -t ca_app_image .
Sending build context to Docker daemon  1.999GB
Step 1/5 : FROM java:8
 ---> d23bdf5b1b1b
Step 2/5 : VOLUME /tmp
 ---> Running in ef9197d4d1ac
 ---> 4bdf99cb32de
Removing intermediate container ef9197d4d1ac
Step 3/5 : EXPOSE 8888
 ---> Running in 528d134466e9
 ---> acdb19d9ba52
Removing intermediate container 528d134466e9
Step 4/5 : RUN bash -c 'touch /tmp/app.jar'
 ---> Running in ad4a57259716
 ---> d1c35ddd53fa
Removing intermediate container ad4a57259716
Step 5/5 : ENTRYPOINT java -Djava.security.egd=file:/dev/urandom -jar /tmp/app.jar
 ---> Running in 399ff7c7cd5c
 ---> fe9c61121134
Removing intermediate container 399ff7c7cd5c
Successfully built fe9c61121134
Successfully tagged ca_app_image:latest
jdev@vmd23690:~$ sudo docker run -v /home/jdev/test:/tmp -p 8888:8080 --name ca_spring_boot ca_app_image
Error: Unable to access jarfile /tmp/app.jar
jdev@vmd23690:~$

what is that? the container shouldn’t ‘touch’ as this will create a file if it doesn’t exist
you just want to USE the jar file.

so remove the RUN bash from the dockerfile

Aah, I understand, but everything else is correct? Should it work?

it should, altho I would copy the jar into a container folder and use it from there, this disconnects the
container from the host volume after startup

I removed the RUN line from the Dockerfile, re-created the image.

jdev@vmd23690:~$ sudo docker build -t ca_app_image .
Sending build context to Docker daemon  2.006GB
Step 1/4 : FROM java:8
 ---> d23bdf5b1b1b
Step 2/4 : VOLUME /tmp
 ---> Running in a157711eb182
 ---> 4b0a32fbdc6e
Removing intermediate container a157711eb182
Step 3/4 : EXPOSE 8888
 ---> Running in 44162418fe96
 ---> 361969a37fe9
Removing intermediate container 44162418fe96
Step 4/4 : ENTRYPOINT java -Djava.security.egd=file:/dev/urandom -jar /tmp/app.jar
 ---> Running in f0b432498afb
 ---> 4151ae125506
Removing intermediate container f0b432498afb
Successfully built 4151ae125506
Successfully tagged ca_app_image:latest

jdev@vmd23690:~$ sudo docker run -v /home/jdev/test:/tmp -p 8888:8080 --name ca_spring_boot ca_app_image
Error: Unable to access jarfile /tmp/app.jar
jdev@vmd23690:~$

ok, I would start the container with -it and use the commandline to see what is going on…

The same

jdev@vmd23690:~$ sudo docker run -it -v /home/jdev/test:/tmp -p 8888:8080 --name ca_spring_boot ca_app_image
Error: Unable to access jarfile /tmp/app.jar