docker java_opts,通过docker-compose将JAVA_OPTS传递到Spring Boot应用程序

I am creating a docker image using below configuration. Once image is ready i want to pass JAVA_OPTS to my docker container, so it can be passed to my spring boot application. Whenever i try to bring up the container i am getting "runtime create failed: container_linux.go:348: starting container process caused "exec: \"java $JAVA_OPTS\": executable file not found in $PATH": unknown" error. Am i missing something ? Any help is really appreciated

Dockerfile

FROM openjdk:8-jdk-alpine

LABEL maintainer="myname@test.com"

# Add a volume pointing to /tmp

VOLUME /tmp

# Make port 8080 available to the world outside this container

EXPOSE 8080

# The application's jar file

ARG JAR_FILE=target/my.jar

# Add the application's jar to the container

ADD ${JAR_FILE} my.jar

ENV JAVA_OPTS=""

# Run the jar file

ENTRYPOINT ["java $JAVA_OPTS","-Djava.security.egd=file:/dev/./urandom","-jar","/my.jar"]

docker-compose

version: '2.1'

services:

service1:

hostname: test

domainname: mydomain.com

image: myimage:latest

container_name: test-container

environment:

- JAVA_OPTS=-Dapp.clients.scheme=http -Dapp.clients.port=9096 -Dserver.port=8082

ports:

- "8082:8082"

解决方案

You shouldn't use java $JAVA_OPTS with ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS"]

The main problem with it is that with this approach you application won't receive the sigterm so in case of graceful shutdown it won't work for you (you will find more about the problem here if you are not aware about that)

If you want customize the java opts on docker environments use JAVA_TOOL_OPTIONS environment property (https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html) and ENTRYPOINT ["java", ...]

With this property you can declare your expected options even in Dockerfile like:

ENV JAVA_TOOL_OPTIONS "-XX:MaxRAMPercentage=80"

And you can easily override it later with external provided docker or kubernetes property.

The JAVA_TOOL_OPTIONS is used by the jib project - more here

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值