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.

  • Is there a way for docker-compose to save and open a docker image?
  • Can't launch openresty docker
  • kubernetes : Containers not starting using private registry
  • Start Docker Containers In Specific Order After Reboot
  • Docker Consul Multiple Containers in single VM setup
  • DockerToolbox for win7 service unavailable error
  • 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?

  • Restrict ssh user to their respective docker container
  • How to read environment variables during a docker image build process?
  • Push container to bluemix registry: 405 Method Not Allowed
  • operation not permitted Error response from daemon: Cannot start container System error: operation not permitted
  • Pycharm and remote interpreter (Docker) shows errors but runs fine
  • Mongodb in Docker: numactl --interleave=all explanation
  • 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.