DNS not working within docker containers when host uses dnsmasq and Google's DNS server are firewalled? - Stack Overflow (../../../cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico@v=ec617d715196) (https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a) (https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a) (Stack Overflow) (https://stackoverflow.com/opensearch.xml) (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html) (../../../cdn.sstatic.net/Shared/stacks.css@v=b2264ccf0463.css) (../../../cdn.sstatic.net/Sites/stackoverflow/primary.css@v=1172447e1393.css) (Feed for question 'DNS not working within docker containers when host uses dnsmasq and Google's DNS server are firewalled?') (https://stackoverflow.com/feeds/question/49998099) (../../../cdn.sstatic.net/Shared/Channels/channels.css@v=2c98e83b4da0.css) (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#content) Skip to main content (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#) (https://stackoverflow.com) Stack Overflow (https://stackoverflow.co/) About Products (https://stackoverflow.co/teams/) For Teams (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-for-teams) Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers (https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-advertising) Advertising Reach devs & technologists worldwide about your product, service or employer brand (https://stackoverflow.co/api-solutions/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=overflow-api) Knowledge Solutions Data licensing offering for businesses to build and improve AI tools and models (https://stackoverflow.co/labs/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=labs) Labs The future of collective knowledge sharing (https://stackoverflow.co/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=about-the-company) About the company (https://stackoverflow.blog/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=blog) Visit the blog (Search…) () Loading… (https://stackoverflow.com) current community (https://stackoverflow.com) (Stack Overflow) Stack Overflow (https://stackoverflow.com/help) help (https://chat.stackoverflow.com/?tab=explore) chat (https://meta.stackoverflow.com) (Meta Stack Overflow) Meta Stack Overflow your communities (https://stackoverflow.com/users/signup?ssrc=site_switcher&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f49998099%2fdns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns) Sign up or (https://stackoverflow.com/users/login?ssrc=site_switcher&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f49998099%2fdns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns) log in to customize your list. (https://stackexchange.com/sites) more stack exchange communities (https://stackoverflow.blog) company blog (Click to show search) (https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f49998099%2fdns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns) Log in (https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f49998099%2fdns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns) Sign up (https://stackoverflow.com/) Home (https://stackoverflow.com/questions) Questions (https://stackoverflow.ai) AI Assist Labs (https://stackoverflow.com/tags) Tags (https://stackoverflow.com/beta/challenges) Challenges (https://chat.stackoverflow.com/rooms/259507/stack-overflow-lobby) Chat (https://stackoverflow.blog/contributed?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=so-blog&utm_content=experiment-articles) Articles (https://stackoverflow.com/users) Users (https://stackoverflow.com/jobs?source=so-left-nav) Jobs (https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&so_source=SiteNav) Companies Collectives Communities for your favorite technologies. (https://stackoverflow.com/collectives-all) Explore all Collectives Teams () Ask questions, find answers and collaborate at work with Stack Overflow for Teams. (https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) Try Teams for free (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) Explore Teams Teams Ask questions, find answers and collaborate at work with Stack Overflow for Teams. (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact) Explore Teams Collectives™ on Stack Overflow Find centralized, trusted content and collaborate around the technologies you use most. (https://stackoverflow.com/collectives) Learn more about Collectives Teams Q&A for work Connect and share knowledge within a single location that is structured and easy to search. (https://stackoverflow.co/teams/) Learn more about Teams (https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a) (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html) DNS not working within docker containers when host uses dnsmasq and Google's DNS server are firewalled? (https://stackoverflow.com/questions/ask) Ask Question (2018-04-24 09:30:29Z) Asked 7 years, 5 months ago Modified (https://stackoverflow.com/questions/49998099/dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns?lastactivity) (2022-07-21 20:49:06Z) 3 years, 2 months ago (Viewed 145,702 times) Viewed 146k times (This question shows research effort; it is useful and clear) (70:3:31e,16:5c9984bb47e0d68b,10:1759964900,16:b958db8d7ed15dfa,8:49998099,b9dc2a76663612049ccfd0d1c61f7fbcefd750e798dfb5cd17f2cd774cd599b4) 49 (This question does not show any research effort; it is unclear or not useful) (70:3:31e,16:bfcd31843d4f01a8,10:1759964900,16:1db63037d23e241f,8:49998099,61c03dcd99f382404e1aaf06ba70de833454a9792774fcb1c7bac4994914cf78) (Save this question.) (https://stackoverflow.com/posts/49998099/timeline) (Show activity on this post.) The symptom is: the host machine has proper network access, but programs running within containers can't resolve DNS names (which may appear to be "can't access the network" before investigating more). $ sudo docker run -ti mmoy/ubuntu-netutils /bin/bash root@082bd4ead733:/# ping www.example.com ... nothing happens (timeout) ... ^C root@082bd4ead733:/# host www.example.com ... nothing happens (timeout) ... ^C (The docker image (https://hub.docker.com/r/mmoy/ubuntu-netutils/) mmoy/ubuntu-netutils is a simple image based on Ubuntu with ping and host included, convenient here since the network is broken and we can't apt install these tools) The issue comes from the fact that docker automatically configured Google's public DNS as DNS server within the container: root@082bd4ead733:/# cat /etc/resolv.conf # 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 8.8.8.8 nameserver 8.8.4.4 This just works in many configurations, but obviously doesn't when the host runs on a network where Google's public DNS are filtered by some firewall rules. The reason this happened is: Docker first tries configuring the same DNS server(s) on the host and within the container. The host runs (http://www.thekelleys.org.uk/dnsmasq/doc.html) dnsmasq , a DNS caching service. dnsmasq acts as a proxy for DNS requests, hence the apparent DNS server in the host's /etc/resolve.conf is nameserver 127.0.1.1 , i.e. localhost. The host's dnsmasq listens only for requests comming from localhost and blocks requests coming from the docker container. Since using 127.0.1.1 within docker doesn't work, docker falls back to Google's public DNS, which do not work either. There may be several reasons why DNS is broken within docker containers. This question (and answers) covers the case where: dnsmasq is used. To check whether this is the case: Run ps -e | grep dnsmasq on the host. If the output is empty, you're not running dnsmasq. Check the host's resolv.conf, it probably contains an entry like nameserver 127.0.1.1 . If it contains nameserver 127.0.0.53 , you're probably running systemd-resolved instead of dnsmasq. If so, you won't be able to use the solution forwading DNS requests to dnsmasq (the one using listen-address=172.17.0.1 ). (https://unix.stackexchange.com/questions/445782/how-to-allow-systemd-resolved-to-listen-to-an-interface-other-than-loopback) systemd-resolved versions earlier than 247 hardcoded the fact that it listens only on the 'lo' interface hence there's no easy way to adapt this solution with these versions . Other answers below will work with systemd-resolved. Google's public DNS is filtered. Run host www.example.com 8.8.8.8 . If it fails or times out, then you are in this situation. What are the solutions to get a proper DNS configuration in this configuration? (https://stackoverflow.com/questions/tagged/docker) (show questions tagged 'docker') docker (https://stackoverflow.com/questions/tagged/dns) (show questions tagged 'dns') dns (https://stackoverflow.com/questions/tagged/localhost) (show questions tagged 'localhost') localhost (https://stackoverflow.com/questions/tagged/dnsmasq) (show questions tagged 'dnsmasq') dnsmasq (https://stackoverflow.com/q/49998099) (Short permalink to this question) Share (https://stackoverflow.com/posts/49998099/edit) () Improve this question (Follow this question to receive notifications) Follow (70:3:31e,16:6bb39977ee1ec65b,10:1759964900,16:101c5faed9b7e150,8:49998099,d5ef4b4ae1ebee022ce03ffdb8bf1df4448b5aafe05d474274bd164a106823f5) (https://stackoverflow.com/posts/49998099/revisions) (show all edits to this post) edited (2022-07-21 20:49:06Z) Jul 21, 2022 at 20:49 Matthieu Moy (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy asked (2018-04-24 09:30:29Z) Apr 24, 2018 at 9:30 (https://stackoverflow.com/users/4830165/matthieu-moy) (Matthieu Moy's user avatar) (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy Matthieu Moy (reputation score 16,917) 16.9k (6 gold badges) 6 6 gold badges (44 silver badges) 44 44 silver badges (71 bronze badges) 71 71 bronze badges (Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.) (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#) Add a comment | (Expand to show all comments on this post) (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#) 7 Answers 7 Sorted by: (https://stackoverflow.com/questions/49998099/dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns?answertab=scoredesc#tab-top) Reset to default (scoredesc) Highest score (default) (trending) Trending (recent votes count more) (modifieddesc) Date modified (newest first) (createdasc) Date created (oldest first) (This answer is useful) (70:3:31e,16:46e8937ef503ada4,10:1759964900,16:6eb76c380ff41f9e,8:50001940,82b84309bc0f6373e5c2080a283c2b4c40e8e76c735b85d0f002b48056f3e1eb) 40 (This answer is not useful) (70:3:31e,16:8ffb1e222bf84c4f,10:1759964900,16:d1c3c31cf374ad2b,8:50001940,2427ebb0691525f4ff58a91a8c0c917f747e63ec88262c5c57fc7d359fd02afb) (Save this answer.) (Loading when this answer was accepted…) (https://stackoverflow.com/posts/50001940/timeline) (Show activity on this post.) A clean solution is to configure docker+dnsmasq so than DNS requests from the docker container are forwarded to the dnsmasq daemon running on the host. For that, you need to (https://github.com/moby/moby/issues/23910#issuecomment-271353348) configure dnsmasq to listen to the network interface used by docker , by adding a file /etc/NetworkManager/dnsmasq.d/docker-bridge.conf : $ cat /etc/NetworkManager/dnsmasq.d/docker-bridge.conf listen-address=172.17.0.1 Then restart network manager to have the configuration file taken into account: sudo service network-manager restart Once this is done, you can add 172.17.0.1 , i.e. the host's IP address from within docker, to the list of DNS servers. This can be done either using the command-line: $ sudo docker run -ti --dns 172.17.0.1 mmoy/ubuntu-netutils bash root@7805c7d153cc:/# ping www.example.com PING www.example.com (93.184.216.34) 56(84) bytes of data. 64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=86.6 ms ... or through docker's configuration file /etc/docker/daemon.json (create it if it doesn't exist): $ cat /etc/docker/daemon.json { "dns": [ "172.17.0.1", "8.8.8.8", "8.8.4.4" ] } (this will fall back to Google's public DNS if dnsmasq fails) You need to restart docker to have the configuration file taken into account: sudo service docker restart Then you can use docker as usual: $ sudo docker run -ti mmoy/ubuntu-netutils bash root@344a983908cb:/# ping www.example.com PING www.example.com (93.184.216.34) 56(84) bytes of data. 64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=86.3 ms (https://stackoverflow.com/a/50001940) (Short permalink to this answer) Share (https://stackoverflow.com/posts/50001940/edit) () Improve this answer (Follow this answer to receive notifications) Follow (70:3:31e,16:d5af65d1025eedf0,10:1759964900,16:4e75c320ec956664,8:50001940,aad9d4f8be85fa23317ca3b31f57b0a7c1ce293087f64ef57ab3b9aac0d2f7ea) answered (2018-04-24 12:39:17Z) Apr 24, 2018 at 12:39 (https://stackoverflow.com/users/4830165/matthieu-moy) (Matthieu Moy's user avatar) (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy Matthieu Moy (reputation score 16,917) 16.9k (6 gold badges) 6 6 gold badges (44 silver badges) 44 44 silver badges (71 bronze badges) 71 71 bronze badges Sign up to request clarification or add additional context in comments. 7 Comments Add a comment (https://stackoverflow.com/users/311567/dashesy) () dashesy (https://stackoverflow.com/users/311567/dashesy) dashesy (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment87298044_50001940) (2018-05-02T16:59:29.453Z) Over a year ago what is "172.17.0.1"? default docker bridge gateway? docker install should automatically take care of this 2018-05-02T16:59:29.453Z+00:00 3 Reply Copy link (https://stackoverflow.com/users/4830165/matthieu-moy) () Matthieu Moy (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment87315519_50001940) (2018-05-03T06:59:58.383Z) Over a year ago That's written in the answer: "172.17.0.1 , i.e. the host's IP address from within docker". The problem is that by default, 172.17.0.1 does not reply to DNS requests (since dnsmasq only listens to the local interface), so just configuring 172.17.0.1 would not be sufficient, one needs some config on the dnsmasq side. I guess docker's developers and packagers decided that installing docker should not modify dnsmasq's config. 2018-05-03T06:59:58.383Z+00:00 4 Reply Copy link (https://stackoverflow.com/users/1885442/szczepan-ho%c5%82yszewski) () Szczepan Hołyszewski (https://stackoverflow.com/users/1885442/szczepan-ho%c5%82yszewski) Szczepan Hołyszewski (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment118771324_50001940) (2021-04-21T10:43:25.7Z) Over a year ago $ cat /etc/NetworkManager/dnsmasq.d/docker-bridge.conf - you lost me right there. A "clean solution" is one where a service (dnsmasq) is completely agnostic as to what other services (docker) will be using it. If a solution requires dnsmasq to be specifically "aware" of docker (as evidenced by a file with "docker" in its name going under dnsmasq.d/ ), then it is not a clean solution. 2021-04-21T10:43:25.7Z+00:00 1 Reply Copy link (https://stackoverflow.com/users/4830165/matthieu-moy) () Matthieu Moy (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment118803056_50001940) (2021-04-22T11:42:08.38Z) Over a year ago If you don't like the fact that the name includes "docker", you can give the file any other name ending with .conf . But in any case, you have to tell dnsmasq to listen properly on 172.17.0.1, because this is where requests coming from docker will be directed. Docker here is a bit more than just a daemon running on the machine, it appears like a separate machine with a separate IP address, and by default dnsmasq will reject its requests. 2021-04-22T11:42:08.38Z+00:00 0 Reply Copy link (https://stackoverflow.com/users/1885442/szczepan-ho%c5%82yszewski) () Szczepan Hołyszewski (https://stackoverflow.com/users/1885442/szczepan-ho%c5%82yszewski) Szczepan Hołyszewski (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment119256014_50001940) (2021-05-10T13:18:25.537Z) Over a year ago What distribution does this solution pertain to? Here on Ubuntu, the directory /etc/NetworkManager does not exist. 2021-05-10T13:18:25.537Z+00:00 1 Reply Copy link Add a comment | Show 2 more comments (This answer is useful) (70:3:31e,16:fadab81552d8d191,10:1759964900,16:21ba172796b1580d,8:49998100,0376120590d915b212caec2930bdaeaee490d4f4004c2f88a744dce64fd1febe) 5 (This answer is not useful) (70:3:31e,16:c61923527fa983a5,10:1759964900,16:87637c9c7efddb45,8:49998100,55c6938b886567b7bb1a083158d355b86ab543c3d43d4052d286e83a5d4cb37e) (Save this answer.) (Loading when this answer was accepted…) (https://stackoverflow.com/posts/49998100/timeline) (Show activity on this post.) A brutal and unsafe solution is to avoid containerization of the network, and use the same network on the host and on the container. This is unsafe because this gives access to all the network resources of the host to the container, but if you do not need this isolation this may be acceptable. To do so, just add --network host to the command-line, e.g. $ sudo docker run -ti --network host mmoy/ubuntu-netutils /bin/bash root@ubuntu1604:/# ping www.example.com PING www.example.com (93.184.216.34) 56(84) bytes of data. 64 bytes from 93.184.216.34: icmp_seq=1 ttl=55 time=86.5 ms 64 bytes from 93.184.216.34: icmp_seq=2 ttl=55 time=86.5 ms (https://stackoverflow.com/a/49998100) (Short permalink to this answer) Share (https://stackoverflow.com/posts/49998100/edit) () Improve this answer (Follow this answer to receive notifications) Follow (70:3:31e,16:b87ec6e5d0f41c5f,10:1759964900,16:c73cafc42a4da711,8:49998100,c8015fc7bc10231cffd91dc42bd34f7109fb6ccbf9c7922bf8d756e15ae04230) answered (2018-04-24 09:30:29Z) Apr 24, 2018 at 9:30 (https://stackoverflow.com/users/4830165/matthieu-moy) (Matthieu Moy's user avatar) (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy Matthieu Moy (reputation score 16,917) 16.9k (6 gold badges) 6 6 gold badges (44 silver badges) 44 44 silver badges (71 bronze badges) 71 71 bronze badges 4 Comments Add a comment (https://stackoverflow.com/users/372484/david-r) () David R. (https://stackoverflow.com/users/372484/david-r) David R. (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment89983660_49998100) (2018-07-24T20:48:23.423Z) Over a year ago (Edited 1 time) Is there a better way than this to fix the issue on systems using systemd-resolved? I'm on Ubuntu 18.04. I did try a custom bridge network, it didn't work. docker network create -d bridge testnet then docker run -it --network=testnet debian:stretch bash and then apt update fails. Oh, and iptables is flushed, and my local machine can nslookup 8.8.8.8 google.com just fine. 2018-07-24T20:48:23.423Z+00:00 0 Reply Copy link (https://stackoverflow.com/users/4830165/matthieu-moy) () Matthieu Moy (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment89992827_49998100) (2018-07-25T06:33:12.46Z) Over a year ago Did you try this option: (https://stackoverflow.com/questions/49998099/dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns/50000642#50000642) (dns not working within docker containers when host uses dnsmasq and googles dns) stackoverflow.com/questions/49998099/… ? You won't get the DNS caching within docker, but that should work with systemd-resolved (only the commands to find the real DNS server should change). 2018-07-25T06:33:12.46Z+00:00 0 Reply Copy link (https://stackoverflow.com/users/4830165/matthieu-moy) () Matthieu Moy (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment89992895_49998100) (2018-07-25T06:35:18.657Z) Over a year ago nslookup 8.8.8.8 google.com => I guess you meant nslookup google.com 8.8.8.8 ? That's the weird part: if this works, you're probably not in the situation described by this question. Try the exact same nslookup or host queries within and outside a container and see what the differences are. 2018-07-25T06:35:18.657Z+00:00 0 Reply Copy link (https://stackoverflow.com/users/754798/x99) () X99 (https://stackoverflow.com/users/754798/x99) X99 (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#comment123579696_49998100) (2021-11-10T08:46:28.943Z) Over a year ago I had this issue and no DNS config solved it at all. But your solution worked fine, thanks a lot! 2021-11-10T08:46:28.943Z+00:00 1 Reply Copy link Add a comment (This answer is useful) (70:3:31e,16:7b1e65c2cbdbb05c,10:1759964900,16:e56333d3338c83f2,8:52242399,cdd401af51da4dee0f5484f8512bc728d4b72dc5d1a25747d9dd02c69eb4713c) 5 (This answer is not useful) (70:3:31e,16:0f080ba153cfab33,10:1759964900,16:4f124a96661a3df2,8:52242399,c66c6a09d67a3cf84c73a56e01e71308d8580d6a7fc963d7cc74863aa70ff8cf) (Save this answer.) (Loading when this answer was accepted…) (https://stackoverflow.com/posts/52242399/timeline) (Show activity on this post.) One way is to use a (https://github.com/docker/libnetwork/issues/1654) user defined network for your container. In that case the container's /etc/resolv.conf will have the nameserver 127.0.0.11 (a.k.a. the Docker's (https://docs.docker.com/v17.09/engine/userguide/networking/configure-dns/) embedded DNS server ), which can forward DNS requests to the host's loopback address properly. $ cat /etc/resolv.conf nameserver 127.0.0.1 $ docker run --rm alpine cat /etc/resolv.conf nameserver 8.8.8.8 nameserver 8.8.4.4 $ docker network create demo 557079c79ddf6be7d6def935fa0c1c3c8290a0db4649c4679b84f6363e3dd9a0 $ docker run --rm --net demo alpine cat /etc/resolv.conf nameserver 127.0.0.11 options ndots:0 If you use (https://docs.docker.com/compose/) docker-compose , it will set up a custom network for your services automatically (with a file format (https://docs.docker.com/compose/compose-file/compose-versioning/#version-2) v2+ ). Note, however, that while docker-compose runs containers in a user-defined network, it still builds them in the default network . To use a custom network for builds you can specify the network parameter in the (https://docs.docker.com/compose/compose-file/#build) build configuration (requires file format (https://docs.docker.com/compose/compose-file/compose-versioning/#version-34) v3.4+ ). (https://stackoverflow.com/a/52242399) (Short permalink to this answer) Share (https://stackoverflow.com/posts/52242399/edit) () Improve this answer (Follow this answer to receive notifications) Follow (70:3:31e,16:dfc0dd95e5555cc5,10:1759964900,16:11ba18c118454e17,8:52242399,745579e7cfb372c70025c89c77c4fa8cd05e29e0313f60bd983e73aece8e8f24) answered (2018-09-09 07:42:40Z) Sep 9, 2018 at 7:42 (https://stackoverflow.com/users/244297/eugene-yarmash) (Eugene Yarmash's user avatar) (https://stackoverflow.com/users/244297/eugene-yarmash) Eugene Yarmash Eugene Yarmash (reputation score 151,602) 152k (44 gold badges) 44 44 gold badges (344 silver badges) 344 344 silver badges (391 bronze badges) 391 391 bronze badges Comments Add a comment (This answer is useful) (70:3:31e,16:680af7ebd1ed2893,10:1759964900,16:feac4a1ca168ca00,8:60115866,940ad545b03b6cf83eaed56f835aff91a990541493fa1cdc31141494d34bd6ea) 2 (This answer is not useful) (70:3:31e,16:e7f3033723f9dfba,10:1759964900,16:f62a17938eff6a91,8:60115866,7925051f34321c45620553e5893700a7fae7fd3ae057da520d303aa371c0e15a) (Save this answer.) (Loading when this answer was accepted…) (https://stackoverflow.com/posts/60115866/timeline) (Show activity on this post.) I just had to deal with this last night and eventually remembered that docker run has a set of options for handling it. I used --dns to specify the DNS server I want the container to use. Works like a champ and no need to hack my docker host. There are other options for the domain name and search suffixes. (https://stackoverflow.com/a/60115866) (Short permalink to this answer) Share (https://stackoverflow.com/posts/60115866/edit) () Improve this answer (Follow this answer to receive notifications) Follow (70:3:31e,16:c839743b4507c257,10:1759964900,16:e47955e630ba62bb,8:60115866,c389903fb11832b171f6f11f21da106d21e35dcc5f4691f05d92d573306d007b) answered (2020-02-07 14:56:17Z) Feb 7, 2020 at 14:56 (https://stackoverflow.com/users/745409/mike-diehn) (Mike Diehn's user avatar) (https://stackoverflow.com/users/745409/mike-diehn) Mike Diehn Mike Diehn (reputation score) 192 (7 bronze badges) 7 7 bronze badges Comments Add a comment (This answer is useful) (70:3:31e,16:efcfa9dcdcb05381,10:1759964900,16:b83241d3ac1839c7,8:50000642,6c057adff845171529b58de7a4bb34a09ba14e7e4dd68ce4da5e6238aaadfa74) 1 (This answer is not useful) (70:3:31e,16:61fffd4c62f96915,10:1759964900,16:cbfd37d03899d104,8:50000642,697f4824b5caf557e0f598ae673793482f261c57c1edbb58e89fc59ce9d3cc78) (Save this answer.) (Loading when this answer was accepted…) (https://stackoverflow.com/posts/50000642/timeline) (Show activity on this post.) Since the automatic DNS discovery is guilty here, you may override the default setting in docker's configuration. First, get the IP of the DNS server dnsmasq is using with e.g.: $ sudo kill -USR1 `pidof dnsmasq` $ sudo tail /var/log/syslog [...] Apr 24 13:20:19 host dnsmasq[2537]: server xx.yy.zz.tt1#53: queries sent 0, retried or failed 0 Apr 24 13:20:19 host dnsmasq[2537]: server xx.yy.zz.tt2#53: queries sent 0, retried or failed 0 The IP addresses correspond to the xx.yy.zz.tt placeholders above. Alternatively, if your system is using systemd-resolve instead of dnsmasq, run: $ resolvectl status | grep 'Current DNS' Current DNS Server: xx.yy.zz.tt You can set the DNS at docker run time with the --dns option: $ sudo docker run --dns xx.yy.zz.tt1 --dns xx.yy.zz.tt2 -ti mmoy/ubuntu-netutils bash root@6c5d08df5dfd:/# ping www.example.com PING www.example.com (93.184.216.34) 56(84) bytes of data. 64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=86.6 ms 64 bytes from 93.184.216.34: icmp_seq=2 ttl=54 time=86.6 ms One advantage of this solution is that there is no configuration file involved, hence no risk of forgetting about the configuration and running into troubles later because of a specific config: you're getting this DNS configuration if and only if you type the --dns option. A drawback is that you won't get any DNS caching in the containers, hence DNS resolution will be slower. Alternatively you may set it permanently in Docker's configuration file, /etc/docker/daemon.json (create it, on the host, if it doesn't exist): $ cat /etc/docker/daemon.json { "dns": ["xx.yy.zz.tt1", "xx.yy.zz.tt2"] } You need to restart the docker daemon to take the daemon.json file into account: sudo service docker restart Then you can check the configuration: $ sudo docker run -ti mmoy/ubuntu-netutils bash root@56c74d3bd94b:/# cat /etc/resolv.conf nameserver xx.yy.zz.tt1 nameserver xx.yy.zz.tt2 root@56c74d3bd94b:/# ping www.example.com PING www.example.com (93.184.216.34) 56(84) bytes of data. 64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=86.5 ms Note that this hardcodes the DNS IP in your configuration files. This is strongly discouraged if your machine is a laptop that connects to different networks, and may be problematic if your internet service provider changes the IP of the DNS servers. (https://stackoverflow.com/a/50000642) (Short permalink to this answer) Share (https://stackoverflow.com/posts/50000642/edit) () Improve this answer (Follow this answer to receive notifications) Follow (70:3:31e,16:0dc7f48d8452445d,10:1759964900,16:d3fc5b0992702a80,8:50000642,6c1eeeede1727aa6b10fec637f842473de9f27a9eca7286a0e4c459da806f502) (https://stackoverflow.com/posts/50000642/revisions) (show all edits to this post) edited (2021-08-26 12:03:37Z) Aug 26, 2021 at 12:03 answered (2018-04-24 11:33:15Z) Apr 24, 2018 at 11:33 (https://stackoverflow.com/users/4830165/matthieu-moy) (Matthieu Moy's user avatar) (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy Matthieu Moy (reputation score 16,917) 16.9k (6 gold badges) 6 6 gold badges (44 silver badges) 44 44 silver badges (71 bronze badges) 71 71 bronze badges Comments Add a comment (This answer is useful) (70:3:31e,16:79882affb9abda67,10:1759964900,16:dc14f66ca522547f,8:50000319,fb1b6ec63502470b69e10c29d1460b0a45c837a0841e8dbee8612d4fc73fc2a9) -1 (This answer is not useful) (70:3:31e,16:a2cefec1038fbe2e,10:1759964900,16:8cfb3da2892be240,8:50000319,6f9389562e81a91500baf0b66076403efeaaa4e77cf24d1ff8f523921608fb74) (Save this answer.) (Loading when this answer was accepted…) (https://stackoverflow.com/posts/50000319/timeline) (Show activity on this post.) Since dnsmasq is the issue, one option is to disable it on the host. This works, but will disable DNS caching for all applications running on the host, hence is a really bad idea if the host is used for applications other than docker. If you're sure you want to go this way, uninstall dnsmasq , e.g. on Debian-based systems like Ubuntu, run apt remove dnsmasq . You may then check that /etc/resolv.conf within the container points to the DNS server used by the host. (https://stackoverflow.com/a/50000319) (Short permalink to this answer) Share (https://stackoverflow.com/posts/50000319/edit) () Improve this answer (Follow this answer to receive notifications) Follow (70:3:31e,16:18d0a3f3bda9d333,10:1759964900,16:f6a2922fde828021,8:50000319,fac7568515b1392691b98fb5eb52d3bda792b6703ff9fc2a4b21f24a23e2f326) answered (2018-04-24 11:16:17Z) Apr 24, 2018 at 11:16 (https://stackoverflow.com/users/4830165/matthieu-moy) (Matthieu Moy's user avatar) (https://stackoverflow.com/users/4830165/matthieu-moy) Matthieu Moy Matthieu Moy (reputation score 16,917) 16.9k (6 gold badges) 6 6 gold badges (44 silver badges) 44 44 silver badges (71 bronze badges) 71 71 bronze badges Comments Add a comment (This answer is useful) (70:3:31e,16:6dc0d47f933b8637,10:1759964900,16:60714d489032213a,8:66717235,c31b2af1ebf56b0991e524743a74e7a844c95e47e4b0ae059f79aed9f3143b70) -1 (This answer is not useful) (70:3:31e,16:5ce355954213840d,10:1759964900,16:86795fbfb6e97c77,8:66717235,bbd54e60734ef93d9a2757651009beb76cfc015371b77e38052416a86e7eefd0) (Save this answer.) (Loading when this answer was accepted…) (https://stackoverflow.com/posts/66717235/timeline) (Show activity on this post.) I had problems with the DNS resolver in our docker containers. I tried a lot of different things, and in the end, I just figured that my VPS in Hostgator didn't have installed by default NetworkManager-tui (nmtui), I just installed and reboot it . sudo yum install NetworkManager-tui And reconfigured my resolv.conf with default DNS as 8.8.8.8 . nano /etc/resolv.conf (https://stackoverflow.com/a/66717235) (Short permalink to this answer) Share (https://stackoverflow.com/posts/66717235/edit) () Improve this answer (Follow this answer to receive notifications) Follow (70:3:31e,16:6cb0a7a34f3edd4c,10:1759964900,16:24ebedf0d718e327,8:66717235,f20001af5beba7bd99e74b971956b3d0f6c9a020c209679babb715e4771e5262) answered (2021-03-20 00:43:34Z) Mar 20, 2021 at 0:43 (https://stackoverflow.com/users/3954514/sebastian-cardona-osorio) (Sebastian Cardona Osorio's user avatar) (https://stackoverflow.com/users/3954514/sebastian-cardona-osorio) Sebastian Cardona Osorio Sebastian Cardona Osorio (reputation score) 495 (8 silver badges) 8 8 silver badges (8 bronze badges) 8 8 bronze badges Comments Add a comment (49998099) (false) () (0) Your Answer (True) (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#) Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question . Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. To learn more, see our (https://stackoverflow.com/help/how-to-answer) tips on writing great answers . Draft saved Draft discarded (16a63166755f4bdd4f6a5c8fb8c4468cb19872abe0d4f9ac7bdb9620ffd88fbd) Sign up or (https://stackoverflow.com/users/login?ssrc=question_page&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f49998099%2fdns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns%23new-answer) log in Sign up using Google Sign up using Email and Password (false) (false) Submit Post as a guest Name () () Email Required, but never shown () () Post as a guest Name () () Email Required, but never shown () () Post Your Answer Discard By clicking “Post Your Answer”, you agree to our (https://stackoverflow.com/legal/terms-of-service/public) terms of service and acknowledge you have read our (https://stackoverflow.com/legal/privacy-policy) privacy policy .(1) Start asking to get answers Find the answer to your question by asking. (https://stackoverflow.com/questions/ask) Ask question Explore related questions (https://stackoverflow.com/questions/tagged/docker) (show questions tagged 'docker') docker (https://stackoverflow.com/questions/tagged/dns) (show questions tagged 'dns') dns (https://stackoverflow.com/questions/tagged/localhost) (show questions tagged 'localhost') localhost (https://stackoverflow.com/questions/tagged/dnsmasq) (show questions tagged 'dnsmasq') dnsmasq See similar questions with these tags. The Overflow Blog (https://stackoverflow.blog/2025/10/07/context-is-king-for-secure-ai-generated-code/) Context is king for secure, AI-generated code (https://stackoverflow.blog/2025/10/08/a-new-look-for-comments/) A new look for comments Featured on Meta (Meta Stack Exchange) (https://meta.stackexchange.com/questions/412987/please-welcome-v2blast-back-to-the-community-team) Please welcome V2Blast back to the Community Team! (Meta Stack Exchange) (https://meta.stackexchange.com/questions/412992/a-first-look-stack-overflow-redesign) A First Look: Stack Overflow Redesign (Meta Stack Overflow) (https://meta.stackoverflow.com/questions/421831/policy-generative-ai-e-g-chatgpt-is-banned) Policy: Generative AI (e.g., ChatGPT) is banned (Meta Stack Overflow) (https://meta.stackoverflow.com/questions/435121/exploring-new-types-of-questions-on-stack-overflow) Exploring new types of questions on Stack Overflow Linked (https://stackoverflow.com/questions/24991136/docker-build-could-not-resolve-archive-ubuntu-com-apt-get-fails-to-install-a) (Question score (upvotes - downvotes)) 146 (https://stackoverflow.com/questions/24991136/docker-build-could-not-resolve-archive-ubuntu-com-apt-get-fails-to-install-a?noredirect=1) Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything (https://stackoverflow.com/questions/56951247/docker-container-host-does-not-resolve-when-i-am-not-connected-to-internet) (Question score (upvotes - downvotes)) 0 (https://stackoverflow.com/questions/56951247/docker-container-host-does-not-resolve-when-i-am-not-connected-to-internet?noredirect=1) Docker container host does not resolve when I am not connected to internet (https://stackoverflow.com/questions/79058615/docker-fails-when-trying-to-install-libraries) (Question score (upvotes - downvotes)) -2 (https://stackoverflow.com/questions/79058615/docker-fails-when-trying-to-install-libraries?noredirect=1) Docker fails when trying to install libraries Related (https://stackoverflow.com/questions/23012273/setting-up-docker-dnsmasq) (Question score (upvotes - downvotes)) 9 (https://stackoverflow.com/questions/23012273/setting-up-docker-dnsmasq) Setting Up Docker Dnsmasq (https://stackoverflow.com/questions/23675098/docker-dns-issue-on-local-machine) (Question score (upvotes - downvotes)) 1 (https://stackoverflow.com/questions/23675098/docker-dns-issue-on-local-machine) Docker DNS issue on local machine (https://stackoverflow.com/questions/29266560/docker-container-can-reach-dns-but-not-resolve-hosts) (Question score (upvotes - downvotes)) 19 (https://stackoverflow.com/questions/29266560/docker-container-can-reach-dns-but-not-resolve-hosts) Docker container can reach DNS but not resolve hosts (https://stackoverflow.com/questions/35519615/docker-container-can-only-access-internet-with-net-host) (Question score (upvotes - downvotes)) 13 (https://stackoverflow.com/questions/35519615/docker-container-can-only-access-internet-with-net-host) Docker container can only access internet with --net=host (https://stackoverflow.com/questions/35693117/how-can-i-give-docker-containers-access-to-a-dnsmasq-local-dns-resolver-on-the-h) (Question score (upvotes - downvotes)) 25 (https://stackoverflow.com/questions/35693117/how-can-i-give-docker-containers-access-to-a-dnsmasq-local-dns-resolver-on-the-h) How can I give Docker containers access to a dnsmasq local DNS resolver on the host? (https://stackoverflow.com/questions/36358331/docker-setting-up-dns-for-containers) (Question score (upvotes - downvotes)) 4 (https://stackoverflow.com/questions/36358331/docker-setting-up-dns-for-containers) Docker: Setting up dns for containers (https://stackoverflow.com/questions/36934572/docker-container-cannot-resolve-hosts) (Question score (upvotes - downvotes)) 37 (https://stackoverflow.com/questions/36934572/docker-container-cannot-resolve-hosts) Docker container cannot resolve hosts (https://stackoverflow.com/questions/38816077/run-dnsmasq-as-dhcp-server-from-inside-a-docker-container) (Question score (upvotes - downvotes)) 14 (https://stackoverflow.com/questions/38816077/run-dnsmasq-as-dhcp-server-from-inside-a-docker-container) Run dnsmasq as DHCP server from inside a Docker container (https://stackoverflow.com/questions/42299839/docker-local-dns) (Question score (upvotes - downvotes)) 1 (https://stackoverflow.com/questions/42299839/docker-local-dns) docker - local DNS (https://stackoverflow.com/questions/53184588/docker-container-not-use-host-dns) (Question score (upvotes - downvotes)) 0 (https://stackoverflow.com/questions/53184588/docker-container-not-use-host-dns) Docker Container not use host DNS (https://stackexchange.com/questions?tab=hot) Hot Network Questions (Travel Stack Exchange) (https://travel.stackexchange.com/questions/200379/have-a-valid-tourist-visa-for-us-recently-quit-my-job-can-i-visit-my-sister-wo) Have a valid tourist visa for US. Recently quit my job, can I visit my sister working in USA (Electrical Engineering Stack Exchange) (https://electronics.stackexchange.com/questions/756583/how-can-i-measure-power-supply-noise-and-ripple-lower-than-100%c2%b5v) How can I measure power supply noise and ripple lower than 100µV? (MathOverflow) (https://mathoverflow.net/questions/501380/remez-type-inequality) Remez-type inequality (English Language & Usage Stack Exchange) (https://english.stackexchange.com/questions/633390/grammatical-perspective-come-go-home) Grammatical perspective: "come/go home" (English Language Learners Stack Exchange) (https://ell.stackexchange.com/questions/368701/is-know-how-color-a-common-expression-or-the-authors-stylistic-device) Is "know-how color" a common expression or the author's stylistic device? (Politics Stack Exchange) (https://politics.stackexchange.com/questions/93704/does-the-continuing-resolution-to-provide-funding-for-the-affordable-care-act-in) Does the continuing resolution to provide funding for the Affordable Care Act include $200 billion for undocumented immigrants over the next decade? (Unix & Linux Stack Exchange) (https://unix.stackexchange.com/questions/800310/cannot-delete-bash-associative-array-element) Cannot delete bash associative array element (Science Fiction & Fantasy Stack Exchange) (https://scifi.stackexchange.com/questions/299518/when-was-dr-who-shown-on-dr-who) When was Dr Who shown on Dr Who? (Electrical Engineering Stack Exchange) (https://electronics.stackexchange.com/questions/756644/reducing-shunt-resistor-value-in-current-source) Reducing shunt resistor value in current source (Science Fiction & Fantasy Stack Exchange) (https://scifi.stackexchange.com/questions/299525/picture-and-story-id-looking-for-an-image-of-an-alien-with-a-raspberry-like-face) Picture and story ID looking for an image of an alien with a raspberry like face (Geographic Information Systems Stack Exchange) (https://gis.stackexchange.com/questions/495645/what-is-the-required-geojson-data-to-import-into-caltopo) What is the required GeoJSON data to import into Caltopo? (Philosophy Stack Exchange) (https://philosophy.stackexchange.com/questions/131040/is-it-possible-to-create-a-language-with-no-paradoxical-statements) Is it possible to create a language with no paradoxical statements? (Physics Stack Exchange) (https://physics.stackexchange.com/questions/860413/why-1st-law-of-thermodynamics-is-applied-to-cosmological-expansion) Why 1st law of thermodynamics is applied to cosmological expansion (Physics Stack Exchange) (https://physics.stackexchange.com/questions/860446/do-rotating-power-tools-such-as-tablesaw-jointer-or-angle-grinder-exert-hundre) Do rotating power tools such as tablesaw, jointer, or angle grinder exert hundreds or thousands of g-forces on their rotating parts? (Super User) (https://superuser.com/questions/1926322/how-to-use-a-lets-encrypt-certificate-on-multiple-servers-in-different-vlans) How to use a Let's Encrypt certificate on multiple servers in different VLANs? (Movies & TV Stack Exchange) (https://movies.stackexchange.com/questions/128556/historical-drama-set-in-the-middle-ages-in-western-europe) Historical drama set in the Middle-Ages in Western Europe (Worldbuilding Stack Exchange) (https://worldbuilding.stackexchange.com/questions/269326/what-sort-of-astronomical-natural-disasters-could-a-type-ii-iii-civilization-not) What sort of astronomical natural disasters could a Type II-III civilization NOT anticipate or avert? (Science Fiction & Fantasy Stack Exchange) (https://scifi.stackexchange.com/questions/299520/what-kind-of-probability-distribution-is-hinted-about-in-words-of-radiance) What kind of probability distribution is hinted about in Words of Radiance? (Science Fiction & Fantasy Stack Exchange) (https://scifi.stackexchange.com/questions/299527/did-c%c3%adrdan-build-a-new-ship-for-every-journey-west) Did Círdan build a new ship for every journey West? (Music: Practice & Theory Stack Exchange) (https://music.stackexchange.com/questions/141550/whats-the-smallest-detectable-shift-in-microtiming) What's the smallest detectable shift in microtiming? (Retrocomputing Stack Exchange) (https://retrocomputing.stackexchange.com/questions/32135/ms-dos-vector-fractal-generator) MS-DOS vector fractal generator? (Mathematics Stack Exchange) (https://math.stackexchange.com/questions/5100409/taylor-series-of-a-finite-degree-polynomial) Taylor Series of a finite degree polynomial (Chemistry Stack Exchange) (https://chemistry.stackexchange.com/questions/191032/what-type-of-cloth-is-used-in-magic-canvas-sets-that-let-you-paint-black-tem) What type of cloth is used in 'magic canvas' sets that let you 'paint' black temporarily with just water? (Worldbuilding Stack Exchange) (https://worldbuilding.stackexchange.com/questions/269309/mapping-political-boundaries-in-the-milky-way-galaxy) Mapping political boundaries in the Milky Way galaxy (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#) more hot questions (https://stackoverflow.com/feeds/question/49998099) (Feed of this question and its answers) Question feed Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. (https://stackoverflow.com/feeds/question/49998099) (dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns.html#) () (https://stackoverflow.com) (https://stackoverflow.com) Stack Overflow (https://stackoverflow.com/questions) Questions (https://stackoverflow.com/help) Help (https://chat.stackoverflow.com/?tab=explore) Chat (https://stackoverflow.co/) Products (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=teams) Teams (https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=advertising) Advertising (https://stackoverflow.co/advertising/employer-branding/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=talent) Talent (https://stackoverflow.co/) Company (https://stackoverflow.co/) About (https://stackoverflow.co/company/press/) Press (https://stackoverflow.co/company/work-here/) Work Here (https://stackoverflow.com/legal) Legal (https://stackoverflow.com/legal/privacy-policy) Privacy Policy (https://stackoverflow.com/legal/terms-of-service/public) Terms of Service (https://stackoverflow.com/contact) Contact Us Your Privacy Choices (https://policies.stackoverflow.co/stack-overflow/cookie-policy) Cookie Policy (https://stackexchange.com) Stack Exchange Network (https://stackexchange.com/sites#technology) Technology (https://stackexchange.com/sites#culturerecreation) Culture & recreation (https://stackexchange.com/sites#lifearts) Life & arts (https://stackexchange.com/sites#science) Science (https://stackexchange.com/sites#professional) Professional (https://stackexchange.com/sites#business) Business (https://api.stackexchange.com/) API (https://data.stackexchange.com/) Data (https://stackoverflow.blog?blb=1) Blog (https://www.facebook.com/officialstackoverflow/) Facebook (https://twitter.com/stackoverflow) Twitter (https://linkedin.com/company/stack-overflow) LinkedIn (https://www.instagram.com/thestackoverflow) Instagram Site design / logo © 2025 Stack Exchange Inc; user contributions licensed under (https://stackoverflow.com/help/licensing) CC BY-SA . rev 2025.10.6.34876