<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="/rss/stylesheet/" type="text/xsl"?>
<rss xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:taxo='http://purl.org/rss/1.0/modules/taxonomy/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd' xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:podbridge='http://www.podbridge.com/podbridge-ad.dtd' version='2.0'>
<channel>
  <title>Jaryl Chng&apos;s Knowledge Base</title>
  <language>en-us</language>
  <generator>microfeed.org</generator>
  <itunes:type>episodic</itunes:type>
  <itunes:explicit>false</itunes:explicit>
  <atom:link rel="self" href="https://kb-jarylchng-com.pages.dev/rss/" type="application/rss+xml"/>
  <link>https://kb.jarylchng.com</link>
  <description>
    <![CDATA[<p>Welcome to the index page of my knowledge base, if you haven't done so, do visit my website at <a href="https://jarylchng.com" rel="noopener noreferrer" target="_blank">https://jarylchng.com</a>.</p><p>I will mainly use this site to document stuff, most of which will likely be in the public domain.</p>]]>
  </description>
  <itunes:author>Jaryl Chng</itunes:author>
  <itunes:image href="https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/channel-c68f1f55f856ab833b4365991609dbec.png"/>
  <image>
    <title>Jaryl Chng&apos;s Knowledge Base</title>
    <url>https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/channel-c68f1f55f856ab833b4365991609dbec.png</url>
    <link>https://kb.jarylchng.com</link>
  </image>
  <copyright>©2024</copyright>
  <itunes:category text="Technology"/>
  <item>
    <title>Docker - Access Docker containers from the host via container names by synchronizing /etc/hosts</title>
    <guid>m3vvl9sdUjw</guid>
    <pubDate>Sun, 14 Apr 2024 06:04:00 GMT</pubDate>
    <itunes:explicit>false</itunes:explicit>
    <description>
      <![CDATA[<p>When using Docker, containers within the same shared network are able to resolve one another via their hostnames. However, the same functionality is not replicated on the host of the Docker containers.</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/m3vvl9sdUjw/image-ab670ddfb37199687af993c4359f53aa.png"></p><p>For personal reasons, I kept Nginx load balancer on the host and did not want to forward ports of containers, but I still wanted to reverse proxy my containers.</p><h2>Solution</h2><h3><a href="https://hub.docker.com/r/jarylc/docker-hosts-sync" rel="noopener noreferrer" target="_blank">https://hub.docker.com/r/jarylc/docker-hosts-sync</a></h3><p>Source: <a href="https://gitlab.com/jarylc/docker-hosts-sync" rel="noopener noreferrer" target="_blank">https://gitlab.com/jarylc/docker-hosts-sync</a></p><p>A simple Golang program that I created that updates the host's /etc/hosts file whenever the Docker containers are updated, capturing the private IPs of all the containers each time. Said program is also packaged in a Docker image, so it is easily appended to your own Docker system!</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/m3vvl9sdUjw/image-f3e9ca5601224962a12949fa7a60168b.png"></p><p>This image automatically mirrors /etc/hosts whenever your Docker containers are changed</p><p><img src="https://kb-static.jarylchng.com/kb-jarylchng-com/production/media/rich-editor/items/m3vvl9sdUjw/image-1d47c873370e880f95d7503aa3d1fd9d.png"></p><h2>Alternatives</h2><h3><a href="https://hub.docker.com/r/jaschweder/hosts" rel="noopener noreferrer" target="_blank">jaschweder/hosts</a></h3><p>Not multi-architecture. Checks every 5 second intervals (not configurable), instead of on container creation and deletion. Big Docker image even when after compression 35mb vs 2.5mb.</p><h3><a href="https://hub.docker.com/r/itsziget/hosts-gen" rel="noopener noreferrer" target="_blank">itsziget/hosts-gen</a></h3><p>Not multi-architecture. Based off a <a href="https://hub.docker.com/r/jwilder/docker-gen" rel="noopener noreferrer" target="_blank">larger templating project</a> for more use-cases, 8mb vs 2.5mb.</p>]]>
    </description>
    <link>https://kb.jarylchng.com/i/docker-access-docker-containers-from-the-host-vi-m3vvl9sdUjw/</link>
    <itunes:episodeType>full</itunes:episodeType>
  </item>
</channel>
</rss>