{"id":19777,"date":"2017-12-20T12:15:12","date_gmt":"2017-12-20T10:15:12","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=19777"},"modified":"2017-12-20T10:41:13","modified_gmt":"2017-12-20T08:41:13","slug":"using-add-host-flag-dns-mapping-within-docker-containers","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/","title":{"rendered":"Using the Add-Host Flag for DNS Mapping within Docker Containers"},"content":{"rendered":"<p>In a <a href=\"https:\/\/www.webcodegeeks.com\/devops\/basics-docker-run-command\/\">previous article<\/a> about the <code>docker run<\/code> command, one of my final thoughts was the following:<\/p>\n<blockquote><p>In this article, we covered quite a few options for the <code>docker run<\/code> command. However, while these options are key, they only scratch the surface of the available options to <code>docker run<\/code>. Some of the options are complex enough to deserve an article unto themselves.<\/p><\/blockquote>\n<p>In today\u2019s article, we are going to do just that: explore a single <code>docker run<\/code> command option. Specifically, we will explore an option that allows us to change DNS within a container.<\/p>\n<p>Today, we will explore the <code>--add-host<\/code> flag.<\/p>\n<h2>What Does Add-Host Do?<\/h2>\n<p>The <code>--add-host<\/code> flag is used to add a single host to IP mapping within a Docker container. This flag can be useful when you need to connect a service within a container to an external host.<\/p>\n<p>To get an understanding of how this works, let\u2019s use the <code>--add-host<\/code> flag to map <code>testing.example.com<\/code> to <code>10.0.0.1<\/code>.<\/p>\n<p>We will be testing with a container named <strong>curl<\/strong>. This container has the <code>curl<\/code> command preinstalled and set as the <a href=\"https:\/\/www.webcodegeeks.com\/devops\/understanding-dockers-cmd-entrypoint-instructions\/\">entrypoint<\/a>. With this container, we can use the <code>curl<\/code> command to connect to our test host.<\/p>\n<p>Before we start adding the <code>--add-host<\/code> flag, let\u2019s see what happens if we use this <strong>curl<\/strong> container to connect to the <code>testing.example.com<\/code> domain.<\/p>\n<pre class=\"brush:php\">$ docker run --rm=True curl -I testing.example.com  \r\ncurl: (6) Could not resolve host: testing.example.com<\/pre>\n<p>We can see from the above, the <code>curl<\/code> command returned an error <code>Could not resolve host<\/code>. This is the typical error we would see when trying to reach a domain that does not have a DNS entry.<\/p>\n<p>This example shows us what happens without any <code>--add-host<\/code> flags added. Let\u2019s see what happens when we use this flag to map <code>testing.example.com<\/code> to <code>10.0.0.1<\/code>.<\/p>\n<pre class=\"brush:php\">$ docker run --rm=True --add-host=testing.example.com:10.0.0.1 curl -I testing.example.com  \r\nHTTP\/1.1 200 OK  \r\nServer: nginx  \r\nDate: Fri, 17 Nov 2017 14:01:20 GMT  \r\nContent-Type: text\/html  \r\nContent-Length: 97652  \r\nLast-Modified: Sun, 16 Jul 2017 11:29:52 GMT  \r\nConnection: keep-alive  \r\nVary: Accept-Encoding  \r\nETag: \"596b4e30-17d74\"  \r\nAccept-Ranges: bytes<\/pre>\n<p>Great! Now when our container reaches out to <code>testing.example.com<\/code>, it is able to connect to our example host. This means our internal DNS resolution works; but how exactly does it work?<\/p>\n<h2>Understanding How Add-Host Works<\/h2>\n<p>To understand how the <code>--add-host<\/code> flag works, let\u2019s spin up a simple <strong>Ubuntu<\/strong> container and take a look around. We can do this by using the <code>-i<\/code> (Interactive) and <code>-t<\/code> (Pseudo-TTY) flags.<\/p>\n<p>These flags will start the container in a mode that allows us to interact with the running process. The process in this case will be <code>\/bin\/bash<\/code>; this gives us a shell within the container. With this shell, we can explore within the container itself.<\/p>\n<pre class=\"brush:php\">$ docker run --rm=True --add-host=testing.example.com:10.0.0.1 -it ubuntu \/bin\/bash  \r\nroot@a87b1beb2eee:\/#<\/pre>\n<p>With our shell startup successful, let\u2019s start looking at this container\u2019s configuration files. Specifically, let\u2019s look at the configurations that drive DNS resolution. The first file we will look at is the <code>\/etc\/nsswitch.conf<\/code> file.<\/p>\n<p>The <code>nsswitch.conf<\/code> file in Unix and Linux is used to define where and how the system will perform name service-related lookups. The specific setting we are interested in is the <code>hosts<\/code> setting. The <code>hosts<\/code> setting is used to define the sources and order used for hostname resolution.<\/p>\n<pre class=\"brush:php\">root@a87b1beb2eee:\/# cat \/etc\/nsswitch.conf  \r\n# \/etc\/nsswitch.conf  \r\n#  \r\n# Example configuration of GNU Name Service Switch functionality.  \r\n# If you have the `glibc-doc-reference' and `info' packages installed, try:  \r\n# `info libc \"Name Service Switch\"' for information about this file.  \r\n\r\npasswd:         compat  \r\ngroup:          compat  \r\nshadow:         compat  \r\ngshadow:        files  \r\n\r\nhosts:          files dns  \r\nnetworks:       files  \r\n\r\nprotocols:      db files  \r\nservices:       db files  \r\nethers:         db files  \r\nrpc:            db files  \r\n\r\nnetgroup:       nis<\/pre>\n<p>In the above, we can see that the <code>hosts<\/code> setting is set to <code>files dns<\/code>. This setting means that for hostname resolution, the system will first consult <strong>files<\/strong>, then <strong>dns<\/strong>.<\/p>\n<p>When our system is performing a DNS lookup, it will first reference local configuration files, such as <code>\/etc\/hosts<\/code>. If the host is not found within <code>\/etc\/hosts<\/code>, the system will then query the name servers defined within the <code>\/etc\/resolv.conf<\/code> configuration file.<\/p>\n<p>Something important to remember is that this methodology is the standard Linux setup. These steps are common for most Linux systems, not just containers.<\/p>\n<p>What does this mean for the <code>--add-host<\/code> flag? Well, it means that there are only two places Docker could change DNS resolution: either the <code>\/etc\/hosts<\/code> file or the name servers referenced in <code>\/etc\/resolv.conf<\/code>.<\/p>\n<p>The most likely candidate is the <code>\/etc\/hosts<\/code> file.<\/p>\n<pre class=\"brush:php\">root@a87b1beb2eee:\/# cat \/etc\/hosts  \r\n127.0.0.1       localhost  \r\n::1     localhost ip6-localhost ip6-loopback  \r\nfe00::0 ip6-localnet  \r\nff00::0 ip6-mcastprefix  \r\nff02::1 ip6-allnodes  \r\nff02::2 ip6-allrouters  \r\n10.0.0.1    testing.example.com  \r\n172.17.0.3      a87b1beb2eee<\/pre>\n<p>If we look at the <code>\/etc\/hosts<\/code> file, we can see an interesting entry.<\/p>\n<pre class=\"brush:php\">10.0.0.1    testing.example.com<\/pre>\n<p>It appears that the <code>--add-host<\/code> flag places an entry into the <code>\/etc\/hosts<\/code> file. What is interesting about this is that editing the <code>\/etc\/hosts<\/code> file is a time-honored sysadmin trick. It has been used for many years to perform just this task: taking an unresolvable hostname and mapping it to a static IP.<\/p>\n<p>!Sign up for a free Codeship Account<\/p>\n<h2>Using Add-Host to Override DNS Resolution<\/h2>\n<p>Another common use of the <code>\/etc\/hosts<\/code> file is overriding normal DNS. Since <code>files<\/code> is listed first within the <code>\/etc\/nsswitch.conf<\/code> configuration file, the <code>\/etc\/hosts<\/code> file is consulted before any traditional DNS name servers.<\/p>\n<p>This means that it is possible to place an entry into the <code>\/etc\/hosts<\/code> file that overrides an existing name. To experiment a little, let\u2019s do this with Google\u2019s domain.<\/p>\n<p>To start our experiment, lLet\u2019s take a look at what normally happens when we use our <strong>curl<\/strong> container to connect to <code>google.com<\/code>.<\/p>\n<pre class=\"brush:php\">$ docker run --rm=True curl -I google.com  \r\nHTTP\/1.1 301 Moved Permanently  \r\nLocation: http:\/\/www.google.com\/  \r\nContent-Type: text\/html; charset=UTF-8  \r\nDate: Fri, 17 Nov 2017 14:04:43 GMT  \r\nExpires: Sun, 17 Dec 2017 14:04:43 GMT  \r\nCache-Control: public, max-age=2592000  \r\nServer: gws  \r\nContent-Length: 219  \r\nX-XSS-Protection: 1; mode=block  \r\nX-Frame-Options: SAMEORIGIN<\/pre>\n<p>From the above, we can see a pretty typical response from <code>google.com<\/code>. Now, let\u2019s see what happens if we use the <code>--add-host<\/code> flag to map <code>google.com<\/code> to <code>10.0.0.1<\/code>.<\/p>\n<pre class=\"brush:php\">$ docker run --rm=True --add-host=google.com:10.0.0.1 curl -I google.com  \r\nHTTP\/1.1 200 OK  \r\nServer: nginx  \r\nDate: Fri, 17 Nov 2017 14:05:52 GMT  \r\nContent-Type: text\/html  \r\nContent-Length: 97652  \r\nLast-Modified: Sun, 16 Jul 2017 11:29:52 GMT  \r\nConnection: keep-alive  \r\nVary: Accept-Encoding  \r\nETag: \"596b4e30-17d74\"  \r\nAccept-Ranges: bytes<\/pre>\n<p>From the above, we can see that our <code>--add-host<\/code> addition resulted in our <code>curl<\/code> command to connect to our example host. What this shows is that the <code>--add-host<\/code> flag can be used for more than mapping an unresolved hostname. It can be used to override traditional DNS as well.<\/p>\n<p>This can be a useful method to force a container to connect to a specific host address.<\/p>\n<h2>Adding Multiple Entries<\/h2>\n<p>Another nice feature of this flag is that it can be specified multiple times.<\/p>\n<pre class=\"brush:php\">$ docker run --rm=True --add-host=1.example.com:10.0.0.1 --add-host=2.example2.com:10.0.0.2 --add-host=3.example.com:10.0.0.3 ubuntu cat \/etc\/hosts  \r\n127.0.0.1       localhost  \r\n::1     localhost ip6-localhost ip6-loopback  \r\nfe00::0 ip6-localnet  \r\nff00::0 ip6-mcastprefix  \r\nff02::1 ip6-allnodes  \r\nff02::2 ip6-allrouters  \r\n10.0.0.1    1.example.com  \r\n10.0.0.2     2.example.com  \r\n10.0.0.3   3.example.com  \r\n172.17.0.3      17796a2cb640<\/pre>\n<p>In the above example, we can see that specifying the <code>--add-host<\/code> multiple times resulted in multiple entries within the <code>\/etc\/hosts<\/code> file. This is true whether multiple hosts are specified (as shown) or if the same host is specified.<\/p>\n<p>This is useful in cases where you may want to specify multiple manual host to IP mappings.<\/p>\n<h2>Summary<\/h2>\n<p>In this article, we explored the <code>--add-host<\/code> flag available with the <code>docker run<\/code> command. We also learned that Docker uses a time-honored sysadmin trick for the heavy lifting behind the <code>--add-host<\/code> flag.<\/p>\n<p>At this point though, you might be thinking, \u201cThis flag is interesting but how can it be used in the real world?\u201d<\/p>\n<p>When creating an application that uses another service, like Redis for example, I tend to have my application configured to reach out to the host of <code>redis<\/code>. I then link a Redis container with that name to my application container. This means my container\u2019s configuration is simple \u2014 it just references <code>redis<\/code>. This works great when I can simply link the Redis container to my application container.<\/p>\n<p>But what happens when the Redis instance can\u2019t be \u201clinked\u201d or is even outside of your control? We would then have to configure the application to reach out to a specific host, somewhat complicating the application\u2019s configuration.<\/p>\n<p>The <code>--add-host<\/code> flag can be a simple way to keep a simplistic application configuration while still enabling the application to connect to the remote instance.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Web Code Geeks with permission by Ben Cane, partner at our <a href=\"http:\/\/www.webcodegeeks.com\/join-us\/wcg\/\" target=\"_blank\" rel=\"noopener\">WCG program<\/a>. See the original article here: <a href=\"https:\/\/blog.codeship.com\/using-the-add-host-flag-for-dns-mapping-within-docker-containers\/\" target=\"_blank\" rel=\"noopener\">Using the Add-Host Flag for DNS Mapping within Docker Containers<\/a><\/p>\n<p>Opinions expressed by Web Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In a previous article about the docker run command, one of my final thoughts was the following: In this article, we covered quite a few options for the docker run command. However, while these options are key, they only scratch the surface of the available options to docker run. Some of the options are complex &hellip;<\/p>\n","protected":false},"author":158,"featured_media":10356,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[217],"class_list":["post-19777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","tag-docker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using the Add-Host Flag for DNS Mapping within Docker Containers - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In a previous article about the docker run command, one of my final thoughts was the following: In this article, we covered quite a few options for the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using the Add-Host Flag for DNS Mapping within Docker Containers - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In a previous article about the docker run command, one of my final thoughts was the following: In this article, we covered quite a few options for the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-20T10:15:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Benjamin Cane\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Cane\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/\"},\"author\":{\"name\":\"Benjamin Cane\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4f5d918df9c19fab91b5b205357ce0b8\"},\"headline\":\"Using the Add-Host Flag for DNS Mapping within Docker Containers\",\"datePublished\":\"2017-12-20T10:15:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/\"},\"wordCount\":1112,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg\",\"keywords\":[\"Docker\"],\"articleSection\":[\"DevOps\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/\",\"name\":\"Using the Add-Host Flag for DNS Mapping within Docker Containers - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg\",\"datePublished\":\"2017-12-20T10:15:12+00:00\",\"description\":\"In a previous article about the docker run command, one of my final thoughts was the following: In this article, we covered quite a few options for the\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DevOps\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/devops\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using the Add-Host Flag for DNS Mapping within Docker Containers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4f5d918df9c19fab91b5b205357ce0b8\",\"name\":\"Benjamin Cane\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/09c6af2f1a7430456089189937094b817ef1b7c75ab9968bfd3ec35d938d914b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/09c6af2f1a7430456089189937094b817ef1b7c75ab9968bfd3ec35d938d914b?s=96&d=mm&r=g\",\"caption\":\"Benjamin Cane\"},\"description\":\"Benjamin Cane is a systems architect in the financial services industry. He writes about Linux systems administration on his blog and has recently published his first book, Red Hat Enterprise Linux Troubleshooting Guide.\",\"url\":\"https:\/\/www.webcodegeeks.com\/author\/benjamin-cane\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using the Add-Host Flag for DNS Mapping within Docker Containers - Web Code Geeks - 2026","description":"In a previous article about the docker run command, one of my final thoughts was the following: In this article, we covered quite a few options for the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/","og_locale":"en_US","og_type":"article","og_title":"Using the Add-Host Flag for DNS Mapping within Docker Containers - Web Code Geeks - 2026","og_description":"In a previous article about the docker run command, one of my final thoughts was the following: In this article, we covered quite a few options for the","og_url":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2017-12-20T10:15:12+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg","type":"image\/jpeg"}],"author":"Benjamin Cane","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Benjamin Cane","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/"},"author":{"name":"Benjamin Cane","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4f5d918df9c19fab91b5b205357ce0b8"},"headline":"Using the Add-Host Flag for DNS Mapping within Docker Containers","datePublished":"2017-12-20T10:15:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/"},"wordCount":1112,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg","keywords":["Docker"],"articleSection":["DevOps"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/","url":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/","name":"Using the Add-Host Flag for DNS Mapping within Docker Containers - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg","datePublished":"2017-12-20T10:15:12+00:00","description":"In a previous article about the docker run command, one of my final thoughts was the following: In this article, we covered quite a few options for the","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/docker-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/devops\/using-add-host-flag-dns-mapping-within-docker-containers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"DevOps","item":"https:\/\/www.webcodegeeks.com\/category\/devops\/"},{"@type":"ListItem","position":3,"name":"Using the Add-Host Flag for DNS Mapping within Docker Containers"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/4f5d918df9c19fab91b5b205357ce0b8","name":"Benjamin Cane","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/09c6af2f1a7430456089189937094b817ef1b7c75ab9968bfd3ec35d938d914b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/09c6af2f1a7430456089189937094b817ef1b7c75ab9968bfd3ec35d938d914b?s=96&d=mm&r=g","caption":"Benjamin Cane"},"description":"Benjamin Cane is a systems architect in the financial services industry. He writes about Linux systems administration on his blog and has recently published his first book, Red Hat Enterprise Linux Troubleshooting Guide.","url":"https:\/\/www.webcodegeeks.com\/author\/benjamin-cane\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/19777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/158"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=19777"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/19777\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/10356"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=19777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=19777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=19777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}