# Custom docker network configuration - container to container comms

**URL:** https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654
**Category:** Self-hosting
**Created:** [April 5, 2018, 3:52pm UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654 "2018-04-05T15:52:23Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 5, 2018, 3:52pm UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/1 "2018-04-05T15:52:23Z")

</div>

I am installing Docker on a host where all applications are already containerised including the main smtp server.

When I try and relay mail from discourse to this smtp server it fails because the server cannot do a reverse lookup on the Discourse server IP. This works fine with my other containers because using docker compose I am allowing access to the mail server docker network using for example something like

```
services:
  php-apache:
     networks:
            - mail_server

networks:
    mail_server:
      external: true

```

How can I achieve this with Discourse so that Discourse service container and the mail server service container can communicate with each other directly?

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [April 5, 2018, 11:50pm UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/2 "2018-04-05T23:50:44Z")

</div>

We don’t use Docker compose (in any of the many forms it has taken over the years), so we’re not going to be able to translate an isolated snippet of its config into anything useful. What are you actually trying to achieve, in general terms? rDNS isn’t usually Docker’s concern, and it’s weird that you’ve got your SMTP server configured to do rDNS lookups on local submission anyway.

---

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 6, 2018, 6:55am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/3 "2018-04-06T06:55:19Z")

</div>

Ok, I will simplify the question.

Docker **container\_a** with a service configured to use Docker _network\_a_ needs to talk to **container\_b** (discourse) using the internal Docker network. With docker compose I would simply add _network\_a_ to the networks configured for the service in container\_b and set it as external.

I could reconfigure and rebuild my mail server but this is working configured as above for all my other docker container services I would rather have it working the same way for Discourse.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [April 6, 2018, 6:57am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/4 "2018-04-06T06:57:50Z")

</div>

What `docker` command line would you run to make what you want to have happen, happen?

---

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 6, 2018, 6:58am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/5 "2018-04-06T06:58:59Z")

</div>

None, I use docker-compose and the yml config example posted in the original question.

I have tried using network args with launcher but this did not work

`./launcher start my_forum --docker-args "–network mail_server"`

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [April 6, 2018, 7:04am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/6 "2018-04-06T07:04:03Z")

</div>

Note the hypothetical implied by the use of the word “would” in my question. I’m not asking what `docker` command line you _do_ run, I’m asking what you _would_ run, were you to eschew the use of docker-compose and instead implement the same configuration without it. It should be at least theoretically possible to ask docker-compose to tell you would it would do, because it just invokes `docker run` behind the scenes anyway, but I doubt sufficient user-friendliness has been built-in. Alternately, you can usually reverse-engineer a command line out of the `docker inspect` output of a correctly configured container.

---

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 6, 2018, 7:07am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/7 "2018-04-06T07:07:32Z")

</div>

OK Matt, thanks for your help. I will eventually figure it out for myself and update this topic with the answer for any other poor unfortunate souls seeking support like myself 🙂

---

<div class="post-metadata">

### Author: ![Cameron\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cameron_d/32/97535_2.png) [@Cameron\_D](https://meta.discourse.org/u/Cameron_D)
#### Post date: [April 6, 2018, 7:25am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/8 "2018-04-06T07:25:20Z")

</div>

Does `docker network connect mail_server [discourse_container_id]` work?

Obviously not ideal because it’ll need to be done again after each bootstrap, but should work until you have a full solution.

---

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 6, 2018, 7:26am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/9 "2018-04-06T07:26:22Z")

</div>

Just tried that Cameron, and yes it works. I think the syntax in my launcher args could be wrong, I am just checking it now.

---

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 6, 2018, 10:50am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/10 "2018-04-06T10:50:57Z")

</div>

Trying to add the network via the launcher args doesn’t seem to work at all.

Manually connecting the network with _network connect_ works but doesn’t register the host name of the discourse service with dockers name resolution system so the mail server hostname lookup (ping my\_forum) fails. So I am back to square one - annoying that a simple docker network config is proving so tricky with discourse.

---

<div class="post-metadata">

### Author: ![Cameron\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cameron_d/32/97535_2.png) [@Cameron\_D](https://meta.discourse.org/u/Cameron_D)
#### Post date: [April 6, 2018, 10:57am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/11 "2018-04-06T10:57:18Z")

</div>

Does it work if you pass `--alias my_forum` to the network connect command?

I just found this too:

> [@Starting Discourse on a Specific Docker Network](https://meta.discourse.org/t/starting-discourse-on-a-specific-docker-network/49401/4):
>
> It looks like I can specify docker args in web\_only.yml though, do you know the syntax for that? Edit: Okay the syntax was really easy, just: docker\_args: “–network squadwars” Now it’s working fine, thank you. (Still doesn’t work from commandline but I don’t care :)) Edit: Well the squadwars network is working fine, but discourse seems to be broken. I’m going to try to add it onto the host network as well, not sure if that works.

(I’ll be trying to get my Discourse instance onto an internal network soon, so I’m interested to see what you get working)

---

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 6, 2018, 11:55am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/12 "2018-04-06T11:55:18Z")

</div>

I saw that post, but I can’t get the networks to connect with the launcher network args option.

I am giving up for now, it looks like it’s going to be far easier to change my mail server setup…

---

<div class="post-metadata">

### Author: ![gaiterjones](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gaiterjones/32/120146_2.png) [@gaiterjones](https://meta.discourse.org/u/gaiterjones)
#### Post date: [April 7, 2018, 8:16am UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/13 "2018-04-07T08:16:06Z")

</div>

After returning to the mail logs I noticed that the email host lookup failure generated a WARNING not an error. Looking at the discourse production logs I saw that discourse was complaining about the mail server certificate

_Job exception: hostname “xxx” does not match the server certificate_

Setting DISCOURSE\_SMTP\_ENABLE\_START\_TLS to false resolved the problem and mail is being delivered.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 15, 2020, 9:25pm UTC](https://meta.discourse.org/t/custom-docker-network-configuration-container-to-container-comms/84654/14 "2020-08-15T21:25:10Z")

</div>


