# Custom nameserver in Docker container

**URL:** https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716
**Category:** Support
**Created:** [17 Febbraio 2016, 4:17am UTC](https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716 "2016-02-17T04:17:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![andybalholm](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@andybalholm](https://meta.discourse.org/u/andybalholm)
#### Post date: [17 Febbraio 2016, 4:17am UTC](https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716/1 "2016-02-17T04:17:16Z")

</div>

I want my Discourse installation to use my local nameserver. (So that it resolves the hostnames of the other computers in the same data center to their LAN addresses instead of the external IP.) The `/etc/resolv.conf` file in the container does include that nameserver, but it puts Google’s nameservers first. Is there any way to customize the content of `resolv.conf`?

---

<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: [17 Febbraio 2016, 8:42am UTC](https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716/2 "2016-02-17T08:42:53Z")

</div>

As far as I’m aware, the container’s `resolv.conf` is copied from the host. So, if the container host has Google’s nameservers, then that’s what the container will get. AFAIK, there’s no way for a container image, nor the command line, to override that behaviour. Of course, you can edit the container’s `resolv.conf` after it is started, but there’s nothing in the Discourse images to do that that I can find. Certainly, the [discourse.org](http://discourse.org) hosting, which uses the same images as are publically available, don’t override `resolv.conf` (it definitely gets copied in from the host).

---

<div class="post-metadata">

### Author: ![andybalholm](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@andybalholm](https://meta.discourse.org/u/andybalholm)
#### Post date: [17 Febbraio 2016, 4:42pm UTC](https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716/3 "2016-02-17T16:42:11Z")

</div>

Well, here is the host’s resolv.conf:

```plaintext
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.33.55.1

```

And here is the one from the container:

```plaintext
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 10.33.55.1

```

---

<div class="post-metadata">

### Author: ![andybalholm](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@andybalholm](https://meta.discourse.org/u/andybalholm)
#### Post date: [26 Febbraio 2016, 7:59pm UTC](https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716/4 "2016-02-26T19:59:24Z")

</div>

More strangeness:

I rebuilt the Discourse container, and edited `resolv.conf` to be just `nameserver 10.33.55.1`, and I could immediately resolve hostnames correctly. But whenever I restart the container, the contents of `resolv.conf` changes to:

```
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 10.33.55.1

```

So something is running when the container starts, and adding the Google nameservers to `resolv.conf`. Or does the container filesystem revert to its previous state whenever it is restarted?

---

<div class="post-metadata">

### Author: ![andybalholm](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@andybalholm](https://meta.discourse.org/u/andybalholm)
#### Post date: [27 Febbraio 2016, 1:23am UTC](https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716/5 "2016-02-27T01:23:01Z")

</div>

I found the documentation on how Docker creates and maintains `/etc/resolv.conf`: [Networking overview | Docker Docs](https://docs.docker.com/engine/userguide/networking/default_network/configure-dns/)

It doesn’t seem to be doing exactly what it says there, but it told me enough to fix the problem. I added the following line to my container’s YAML file:

```
docker_args: --dns=10.33.55.1

```

And now I get the `resolv.conf` file I need.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [8 Giugno 2024, 12:45pm UTC](https://meta.discourse.org/t/custom-nameserver-in-docker-container/39716/6 "2024-06-08T12:45:48Z")

</div>

Questo argomento è stato chiuso automaticamente dopo 3034 giorni. Non sono più consentite nuove risposte.
