title: Can not make containers communicate despite being in the same network
body: <p>Hello i am trying to make a <code>.NET Core</code>server communicate with a <code>Redis</code> database.The server works well outside of the container.<br>The containers are set up.I can access the database using the host-port mapping .<br>However when i am doing an operation that requires the server to call the database the connection gets refused.</p>
  
  <p><strong>dockercompose</strong></p>
  
  <pre><code>version: '3.3'
      services:
             db:
                image: redis:4.0.5-alpine
                container_name: redis0
                networks:
                  - redis-net
                ports:
                  - 6381:6379   //i can acess redis from the hostmachine via 6381  but i can't acess it via 6379 from the container with the server
  
              backend:
                image: server
                container_name: server0
                build: ./Server
                command: ["dotnet","Server.dll"]
                ports:
                  - 9400:9300
                networks:
                  - redis-net
                environment:
                  - dbport=6379
                depends_on:
                  - db
  
          networks:
              redis-net:
  </code></pre>
  
  <p><strong>Startup</strong></p>
  
  <pre><code> public void ConfigureServices(IServiceCollection services) {
  
              services.AddOptions();
              services.AddMvc();
  
      try {
              var env = Environment.GetEnvironmentVariables();
              var portStr = env["dbport"].ToString();
              System.IO.File.AppendAllText("dock.txt",$"dbport:{portStr}");
              if (!(int.TryParse(portStr,out int redisPort))) {
                  return;
              }
  
              var mux = new Multiplexer();
              var logicalConnection = mux.OpenLink(redius.Address.Create(redisPort));
              services.AddSingleton(logicalConnection);
  
          } catch (Exception ex) {
  
              Console.WriteLine("Could not open link, ex:" + ex.Message);
          }
      }
  </code></pre>
  
  <p>For debugging i am writing the <code>exception</code> that the server throws inside a file in the container and i look it up using <code>docker exec -it &lt;container_id&gt; bash</code></p>
  
  <p><strong>Controller Method that throws</strong> </p>
  
  <pre><code> public async Task&lt;List&lt;User&gt;&gt; GetUsers()
          {
              try
              {
                  var usersRaw = await this.connection.HMGetAllAsync("users");
              }
              catch (Exception ex)
              {
                  System.IO.File.AppendAllText(Constants.OUTPUT,ex.Message);
                  return null;
              }
              return null;
  
          }
  </code></pre>
  
  <p>The error says : <code>connection refused for 127.0.0.1:6379</code>.Is the <code>ip</code> address wrong? Basically the problem is the following:</p>
  
  <pre><code>                Redis    Server
  HostPort        6381     9400
  ContainerPort   6379     9300
  AppPort         6379     9300
  </code></pre>
  
  <p>I can acess Redis from outside via <code>6381</code> and i can also acess <code>Server</code> via <code>9400</code>.
  Server can communicate with a <code>Redis</code> both outside containers (so no proprietary library fault).<br>
  Can not access <code>Redis</code> from the <code>Server</code> via <code>6379</code> (both being in the <code>network</code> -> <code>redis-net</code>)</p>