title: How to connect to rabbitmq container from the application server container
body: <p>I am new to docker and I am trying to dockerize this application I have written in Golang. It is a simple web server that interacts with rabbitmq and mongodb</p>
  
  <p>It takes the creadentials form a toml file and loads it into a config struct before starting the application server on port 3000. These are the credentials</p>
  
  <pre><code>mongo_server = "localhost"
  database = "collect_db"
  rabbitmq_server = "amqp://guest:guest@localhost:5672/"
  </code></pre>
  
  <p>If it can't connect to these urls it fails with an error. Following is my docker-compose.yml</p>
  
  <pre><code>version: '3'
  services:
    rabbitmq:
      image: rabbitmq 
      ports:
        - 5672:5672
    mongodb:
      image: mongo
      ports:
        - 27017:27017
    web:
      build: .
      image: palash2504/collect
      container_name: collect_service
      ports:
        - 3000:3000
      depends_on:
        - rabbitmq
        - mongodb
      links: [rabbitmq, mongodb]
  </code></pre>
  
  <p>But it fails to connect with rabbitmq on the url used for local development i.e. <code>amqp://guest:guest@localhost:5672/</code></p>
  
  <p>I realise that the rabbitmq container might be running on some different address other than the one provided in the config file. </p>
  
  <p>I would like to know the correct way for setting any env credentials to be able to connect my app to rabbitmq. </p>
  
  <p>Also what approach would be best to change my application code for initializing connections to external services? I was thinking about ditching the config.toml file and using os.Getenv and os.Setenv to get the urls for connections.</p>