Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read docker env variables into Java code

I am trying to dockerize my Java application which tries to connect to a Rabbitmq server. I have passed the Rabbitmq Url via docker env variable and readig the same url using

System.getenv("RABBITMQ_URL")

, but it came out to be null. Is there anything wrong with the way I am reading the docker env variable ? Here is my Docker create command :

docker service create --name xxx --env RABBITMQ_URL=amqp://rabbitmq:xxxx --network msgq --with-registry-auth ${imageName}

like image 203
sudarshan kakumanu Avatar asked Jul 01 '26 14:07

sudarshan kakumanu


1 Answers

This is weird but, restarting the docker container just worked fine for me. Turns out , i have to restart the container when ever I update the network connection using "--network". Thanks

like image 66
sudarshan kakumanu Avatar answered Jul 03 '26 03:07

sudarshan kakumanu