<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jarle Fosen</title>
    <description>The latest articles on DEV Community by Jarle Fosen (@jarlefosen).</description>
    <link>https://dev.to/jarlefosen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F142122%2Fa0a87178-4876-4cf2-9d25-eb3c06b15910.png</url>
      <title>DEV Community: Jarle Fosen</title>
      <link>https://dev.to/jarlefosen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jarlefosen"/>
    <language>en</language>
    <item>
      <title>Docker exposes itself to your LAN</title>
      <dc:creator>Jarle Fosen</dc:creator>
      <pubDate>Mon, 28 Oct 2024 16:32:25 +0000</pubDate>
      <link>https://dev.to/jarlefosen/docker-exposes-itself-to-your-lan-58pk</link>
      <guid>https://dev.to/jarlefosen/docker-exposes-itself-to-your-lan-58pk</guid>
      <description>&lt;h3&gt;
  
  
  TL;DR
&lt;/h3&gt;

&lt;p&gt;Docker binds to IP &lt;code&gt;0.0.0.0&lt;/code&gt; by default, meaning that all containers exposed on your machine are also accessible to anyone who can reach your IP address.&lt;/p&gt;

&lt;p&gt;This is very useful for a server that serves content online, but not necessarily so useful for local development.&lt;/p&gt;

&lt;p&gt;You can change the default by setting &lt;code&gt;"ip": "127.0.0.1"&lt;/code&gt; in &lt;code&gt;daemon.json&lt;/code&gt;.&lt;br&gt;
See &lt;a href="https://docs.docker.com/engine/network/packet-filtering-firewalls/#default-bridge" rel="noopener noreferrer"&gt;here&lt;/a&gt; for more information.&lt;/p&gt;


&lt;h3&gt;
  
  
  Are you exposing your containers to your friends?
&lt;/h3&gt;

&lt;p&gt;If you use Docker you might be familiar with running commands like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 8080:80 my-cool-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It starts a container from the &lt;code&gt;my-cool-service&lt;/code&gt; image and exposes the container port &lt;code&gt;80&lt;/code&gt; on the host machine port &lt;code&gt;8080&lt;/code&gt;. But it doesn't stop there. By default on Mac this also exposes your cool service to anyone who can access your IP address - which typically would be everyone on the same LAN.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;By default Docker binds to the IP &lt;code&gt;0.0.0.0&lt;/code&gt; which means it accepts incoming connections to all IPv4 interfaces on your machine. This makes sense if you run Docker on a server and expect people to be able to access your content.&lt;br&gt;
But locally you may not want this as the default behavior. Especially if you run a database for local development without any changing the default password.&lt;/p&gt;
&lt;h3&gt;
  
  
  Fear not, you can change this behavior!
&lt;/h3&gt;

&lt;p&gt;In the Docker &lt;code&gt;daemon.json&lt;/code&gt; config file you have the ability to set which IP it binds to by default.&lt;br&gt;
By setting this to &lt;code&gt;127.0.0.1&lt;/code&gt; it will only accept connections from your own machine.&lt;br&gt;
&lt;a href="https://docs.docker.com/engine/network/packet-filtering-firewalls/#default-bridge" rel="noopener noreferrer"&gt;https://docs.docker.com/engine/network/packet-filtering-firewalls/#default-bridge&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you need to expose a service to your friends on the same LAN, you can easily do so when starting up a container&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# docker run -p HOST_IP:HOST_PORT:CONTAINER_PORT IMAGE&lt;/span&gt;
docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 0.0.0.0:8080:80 my-cool-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>docker</category>
      <category>ip</category>
      <category>lan</category>
    </item>
  </channel>
</rss>
