A Docker footgun led to a vandal deleting NewsBlur's MongoDB database (2021)
When I first read the original post, I felt inclined to shift the &quot;blame&quot; on the author, much like they shifted it on Docker, though they are aware of how this footgun can also be a benefit to some:<p>&gt; It would make for a much more dramatic read if I was hit through a vulnerability in Docker instead of a footgun. By having Docker silently override the firewall, Docker has made it easier for developers who want to open up ports on their containers at the expense of security.<p>When I want to run my own web server on an arbitrary Linux distro inside of a container, I want to bind to 0.0.0.0:80 and 0.0.0.0:443. That&#x27;s it.<p>When I want to run my own database on an arbitrary Linux distro inside of a container, without making it accessible externally, I want to just omit exposing ports. That&#x27;s it.<p>I don&#x27;t want to think about the firewall on the system (even what kind of a firewall it is running, if any) or configure it separately, otherwise it&#x27;d be as bind mount target directories on host system not being automatically created, making me use &quot;mkdir -p PATH&quot;, which already adds unnecessary friction (if I want the files to be available in the host OS, as opposed to just in abstracted away Docker volumes). After all, if there were more steps, then an awkward dance would inevitably start: &quot;Hey, we launched the container on SOME_DISTRO but we can&#x27;t access the UI&#x2F;API&#x2F;whatever.&quot; and you&#x27;d have to write platform-specific instructions, as opposed to being able to just give a Docker Compose file or an equivalent and be done with it.<p>Thus, my original thoughts were along the lines of: &quot;It&#x27;s not at the expense of security, as much as it is to the benefit of your convenience without any changes to security, if you are aware of what you are doing.&quot; though that isn&#x27;t charitable enough. Something like this would be more helpful instead:<p><pre><code>  # Suppose you want to let people know that your container wants to listen on the port 2000
  # You can specify it in the Dockerfile, though this will be more like documentation for the container, as opposed to publishing anything
  # Docs: https:&#x2F;&#x2F;docs.docker.com&#x2F;engine&#x2F;reference&#x2F;builder&#x2F;#expose
  # File: Dockerfile
  EXPOSE 2000&#x2F;tcp
  ...
  
  # If you want your port to be available locally, then Docker gives you that ability as well
  # You can even change the port, for example, to 2005 on the host
  # Docs: https:&#x2F;&#x2F;docs.docker.com&#x2F;compose&#x2F;compose-file&#x2F;compose-file-v3&#x2F;#ports
  # File: docker-compose.yml
  ports:
    - &quot;127.0.0.1:2005:2000&#x2F;tcp&quot;
  ...
  
  # If you want your port to be available remotely, then you can either omit the IP address or use 0.0.0.0
  # Let&#x27;s take the above example and use 2005 as the exposed port again
  # File docker-compose.yml
  ports:
    - &quot;2005:2000&#x2F;tcp&quot;
  ...
  
  # For examples of Docker CLI without Docker Compose&#x2F;Swarm, have a look at the docs: https:&#x2F;&#x2F;docs.docker.com&#x2F;config&#x2F;containers&#x2F;container-networking&#x2F;
  # There&#x27;s also good information there about additional networking options, such as creating custom networks for limiting what can talk to what.
</code></pre>
Actually, here&#x27;s an example that anyone can run, with Docker CLI (using the httpd web server as example, same idea applies to DBs):<p><pre><code>  # Launch everything (detached, so we can use the same terminal session, remove containers once stopped)
  docker run -d --rm --name &quot;net_test_not_exposed&quot; httpd:alpine3.17
  docker run -d --rm --name &quot;net_test_local_access&quot; -p &quot;127.0.0.1:2005:80&#x2F;tcp&quot; httpd:alpine3.17
  docker run -d --rm --name &quot;net_test_public_access&quot; -p &quot;0.0.0.0:2006:80&#x2F;tcp&quot; httpd:alpine3.17
  docker run -d --rm --name &quot;net_test_public_access_shorthand&quot; -p &quot;2007:80&quot; httpd:alpine3.17
  
  # Check that everything is running
  docker ps
  
  # Or different formatting
  docker ps --format &quot;{{.Names}} is {{.Status}} with ports {{.Ports}}&quot;
  
  # Then you can use a browser to check them, or do it manually, either locally or from another node (with actual IP address)
  # 2005 will be available locally, whereas 2006 and 2007 will be available remotely
  curl http:&#x2F;&#x2F;127.0.0.1:2005
  curl http:&#x2F;&#x2F;127.0.0.1:2006
  curl http:&#x2F;&#x2F;127.0.0.1:2007
  
  # Finally, the cleanup (the --rm will get rid of the containers)
  docker kill net_test_not_exposed net_test_local_access net_test_public_access net_test_public_access_shorthand
</code></pre>
I will say that this is a good suggestion:<p>&gt; Better would be for Docker to issue a warning when it detects that the most popular firewall on Linux is active and filtering traffic to a port that Docker is about to open.<p>However, the thing with warnings is that they&#x27;re easy to miss. Either way, I&#x27;ve been there - when I was learning Docker a number of years back, I left its socket open and by the morning the tiny VPS was mining crypto. Good docs help, maybe exposing things publicly by default with a port binding or even using the shorthand in the first place isn&#x27;t such a good idea either.