Using environment variables post docker container linking in java

I am trying to simulate docker container linking using a simple use case which is as follows

1) A docker container with a simple pub-sub java application, there is a publisher and subscriber both within the same container. I have used dockerfiles for building this
2) A docker container running rabbitmq, this was pulled from docker hub.

  • Docker and package managers in production
  • Have docker container connect to network devices
  • docker to connect with mysql database of host system and dump the sql file into host system and then host a web application
  • Cloning GitHub private repository with Docker container non-root user?
  • docker build: Returned a non-zero code: 2
  • docker run --cpuset is not having any effect
  • Now I link both the containers, I am able to see rabbitmq environment variables in my container #1.

    Now my question is what is the best way to utilize these container variables in my pub-sub container #1. I can always java System.getenv and hardcode a environment variable. Are there any better ways of doing it?

  • Copy multiple files in docker with cp
  • Using docker to run a distributed computation
  • How do I set System Path in my dockerfile for a Windows Container?
  • Rancher slow performance deploying new docker image
  • Running Desktop Apps on Docker Containers on Windows 10
  • Why is kubernetes source code an order of magnitude larger than other container orchestrators? [closed]
  • One Solution collect form web for “Using environment variables post docker container linking in java”

    Hard-coding an environment variable seems OK here. The environment variables follow a standard format, like RABBITMQ_PORT_5672_TCP_ADDR and RABBITMQ_PORT_5672_TCP_PORT. The only bit of those names which would change is the label RABBITMQ, which is set based on the options to docker run. Whoever runs your container controls that bit, either with --link rabbitmq or --link someothercontainer:rabbitmq to set an alias. This just forms part of your container’s “contract” with the outside world: the container must be run in a way that adds variables with the right alias.

    Incidentally, this doesn’t force you to use Docker links if you don’t want to, as you can always just pass in the environment variables if Rabbit MQ were on a different machine (e.g. --env RABBITMQ_PORT_5672_TCP_ADDR=

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.