如何将docker env变量读入Java代码 [英] How to read docker env variables into Java code

查看:582
本文介绍了如何将docker env变量读入Java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将试图连接到Rabbitmq服务器的Java应用程序码头化。我已经通过docker env变量传递了Rabbitmq Url,并使用

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)

System.getenv("RABBITMQ_URL")

,但是它为空。我读取docker env变量的方式有什么问题吗?这是我的Docker创建命令:

, 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}

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


推荐答案

这很奇怪,但是重新启动docker容器对我来说很好。事实证明,每当我使用 --network更新网络连接时,都必须重新启动容器。谢谢

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

这篇关于如何将docker env变量读入Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆