简体   繁体   中英

Docker Compose JVM parameters

I wrote a java application that takes an environment variable that takes an argument to set a key for a JWT token salt key. Is there a way for me to pass the command variables in Docker Compose?

java -Djava.security.egd=file:/dev/./urandom -jar /user-profile-api.jar --key=blah

And to run the docker image you just

docker run -p 8080:8080 docker_image --key=blah

If you already are able to run your docker container using:

docker run -p 8080:8080 docker_image --key=blah

Then you just need to override the command attribute for your service in the compose file to --key=blah. So:

services:
  app:
    command: --key=blah
...

One way would be to put your java command in a shell script (say, bootstrap.sh ), and set that as your command to run in docker compose. And then in bootstrap.sh inject the key via an environment variable which is in your docker-compose.yml .

Eg

bootstrap.sh

java -Djava.security.egd=file:/dev/./urandom -jar /user-profile-api.jar --key=$SALT_KEY

docker-compose.yml

build: .
environment:
    - SALT_KEY=blah
command: /opt/app/bootstrap.sh

Obviously you'd need to package up bootstrap.sh into your container for this to work.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM