Reputation: 6588
I want to run a jar on a docker container, it was working fine, but if I use a jar that need to read from a config file it fail.
The next is my docker-compose.yml:
jar:
image: frolvlad/alpine-oraclejdk8:slim
ports:
- "3000:3000"
volumes:
- /tmp
- "./farr-api-0.1.0.jar:/fagor/app.jar"
- "./config/application.yml:/fagor/config/application.yml"
command: sh -c 'touch /fagor/app.jar'
environment:
- JAVA_OPTS=""
entrypoint: [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /fagor/app.jar" ]
Exceptions:
jar_1 | Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
jar_1 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:62)
jar_1 | at java.lang.Thread.run(Thread.java:745)
jar_1 | Caused by: java.lang.reflect.InvocationTargetException
jar_1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
jar_1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
jar_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
jar_1 | at java.lang.reflect.Method.invoke(Method.java:498)
jar_1 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54)
jar_1 | ... 1 more
jar_1 | Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private long es.ikerlan.farr_api.config.AppConfig.id; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'plants[0].plant.id' in string value "${plants[0].plant.id}"
Upvotes: 3
Views: 1891
Reputation: 1324
Here is a simple dockerfile that copies your app to an image, mounts a volume and copies the config to the volume.
FROM frolvlad/alpine-oraclejdk8:slim
MAINTAINER Asier
VOLUME /config
COPY your_app.jar app.jar
COPY your_config.yml config/application.yml
RUN touch /app.jar
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
compose file can be simple like
version: '2'
services:
farrapi_container:
container_name: farrapicontainer
build:
context: ./
dockerfile: Dockerfile
ports:
- "3000:3000"
By that you should be able to change config via host. Be sure that app references the config file properly. Anyways I would still try to have the configuration done via environment settings. It's pretty straight forward to override settings in you application.properties with ENV settings in spring boot.
Upvotes: 3
Reputation: 2363
This's not an answer, just want to show how to test the jar
with docker run
. Now we are:
docker run -it -p 3000:3000 \
-v ./farr-api-0.1.0.jar:/fagor/app.jar \
-v ./config/application.yml:/fagor/config/application.yml \
frolvlad/alpine-oraclejdk8:slim \
/bin/bash
# Now when you're inside the container
# Make sure you can run Java
java -version
# Make sure you had your files
ls -la /fagor/app.jar
ls -ls /fagor/config/application.yml
# Run it
export JAVA_OPTS=""
java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /fagor/app.jar
Upvotes: 2