Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vert.x based application crashes on docker container

I'm trying to run a Vert.x Java based application on a Docker container. My application runs few verticles which it initiates from within itself. I've put the jar file on a folder and created a Dockerfile with the following content:

FROM vertx/vertx3
ENV VERTICLE_FILE Medical-1.0-SNAPSHOT.jar 
ENV VERTICLE_HOME /performit/web/vertx/verticles/
COPY $VERTICLE_FILE $VERTICLE_HOME/  
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
EXPOSE 8080
CMD ["java -jar $VERTICLE_FILE"]
USER daemon

I create an image with the command

$ sudo docker build -t medical-main .

I then attempt to create a container with the following line:

sudo docker run --name medical-main -p 8080:8080 -d  medical-main

This fails and the log shows the following:

java.lang.IllegalStateException: Failed to create cache dir
at io.vertx.core.impl.FileResolver.setupCacheDir(FileResolver.java:257)
at io.vertx.core.impl.FileResolver.<init>(FileResolver.java:79)
at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:138)
at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:114)
at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:110)
at io.vertx.core.impl.VertxFactoryImpl.vertx(VertxFactoryImpl.java:34)
at io.vertx.core.Vertx.vertx(Vertx.java:79)

What am I missing?

Izhar

like image 491
Izhar Lotem Avatar asked Mar 02 '16 13:03

Izhar Lotem


4 Answers

Judging by FileResolver.java, vert.x tries to create a ".vertx" directory in the current working directory by default. You have configured a user called "daemon", are you sure that this user has write access to the working dir in the docker image? If not, change the permissions as outlined in docker-image-author-guidance, or revert to using the root user.

like image 173
Alexander Torstling Avatar answered Nov 19 '22 17:11

Alexander Torstling


This directory is used to serve files contained in jar files (for example web assets packaged in a fat jar). If you are not using this feature, you can disable the creation of this directory by setting the vertx.disableFileCPResolving system property to true. You can also change the location using the vertx.cacheDirBase system property.

Reference: https://groups.google.com/forum/#!topic/vertx/7cBbKrjYfeI

like image 26
Jayati Avatar answered Nov 19 '22 18:11

Jayati


This exception is caused when Vert.x tries to create .vertx (cache dir) so that it can copy and read a file from the classpath or file that's on the classpath. It's possible, the $user doesn't have permission to create the cache directory.

The reason behind cache dir is simple: reading a file from a jar or from an input stream is blocking. So to avoid to pay the price every time, Vert.x copies the file to its cache directory and reads it from there every subsequent read. This behavior can be configured.

vertx run my.Verticle -Dvertx.cacheDirBase=/tmp/vertx-cache
# or
java -jar my-fat.jar -Dvertx.cacheDirBase=/tmp/vertx-cache

Otherwise, you can completely avoid this behavior, launch your application with -Dvertx.disableFileCaching=true. With this setting, Vert.x still uses the cache, but always refresh the version stored in the cache with the original source. So if you edit a file served from the classpath and refresh your browser, Vert.x reads it from the classpath, copies it to the cache directory and serves it from there. Do not use this setting in production, it can kill your performances.

link to documentation

like image 4
Simple-Solution Avatar answered Nov 19 '22 17:11

Simple-Solution


For me, this same issue was coming for while trying to run a jar file. It started coming suddenly and then I was forced to run the jar file as ROOT for sometime until I finally got fed up and started looking for reason thoroughly.

It happened because I accidentally ran jar file once in SUDO privileges and the .vertx folder was create as ROOT account.

I could not figure this out initially as I was trying ll alias command in amazon linux and sadly it does not display hidden folders

So when I was thoroughly investigating the issue next time, I also tried ls -al which showed in .vertx folder and I figured out that issue was it being created as SUDO user.

Deleted .vertx folder and jar file started working normally again as normal user.

like image 3
Aditya T Avatar answered Nov 19 '22 18:11

Aditya T