Skip to content

Instantly share code, notes, and snippets.

@serious-angel
Created February 5, 2026 03:04
Show Gist options
  • Select an option

  • Save serious-angel/9df07228bd89a2179b279597f06a59c5 to your computer and use it in GitHub Desktop.

Select an option

Save serious-angel/9df07228bd89a2179b279597f06a59c5 to your computer and use it in GitHub Desktop.
[Docker] Example of service with limited network access
services:
first:
image: nginx
networks:
# Dsable the default bridge explicitly, with no known Internet access.
- isolated
# For the container access with its custom subnet/network.
- between
second:
# image: ubuntu
image: nicolaka/netshoot
command: sleep infinity
networks:
# For default but configurable Docker bridge (e.g. for the default gateway with Internet access).
- default
# For the container access with its custom subnet/network.
- between
networks:
between:
driver: bridge
internal: true
isolated:
driver: bridge
internal: true
ipam:
driver: default
config:
- subnet: '10.0.1.0/24'

Within isolated "First" service container

╴$ docker compose exec -it first bash;
root@a4bc468d1b98:/# curl google.com
curl: (6) Could not resolve host: google.com

root@a4bc468d1b98:/# curl 142.251.141.110;
curl: (7) Failed to connect to 142.251.141.110 port 80 after 0 ms: Could not connect to server

root@a4bc468d1b98:/# curl first;
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

root@a4bc468d1b98:/# curl -v second;
* Host second:80 was resolved.
* IPv6: (none)
* IPv4: 172.24.0.2
*   Trying 172.24.0.2:80...
* connect to 172.24.0.2 port 80 from 172.24.0.3 port 42112 failed: Connection refused
* Failed to connect to second port 80 after 2 ms: Could not connect to server
* closing connection #0
curl: (7) Failed to connect to second port 80 after 2 ms: Could not connect to server

Within "Second" service container

$ docker compose exec -it second bash;
73c3200d6cc2:~# curl first;
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

73c3200d6cc2:~# curl second;
curl: (7) Failed to connect to second port 80 after 0 ms: Could not connect to server

73c3200d6cc2:~# curl -v second;
* Host second:80 was resolved.
* IPv6: (none)
* IPv4: 172.25.0.2
*   Trying 172.25.0.2:80...
* connect to 172.25.0.2 port 80 from 172.25.0.2 port 49426 failed: Connection refused
* Failed to connect to second port 80 after 2 ms: Could not connect to server
* closing connection #0
curl: (7) Failed to connect to second port 80 after 2 ms: Could not connect to server

73c3200d6cc2:~# curl google.com;
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

Within the host

# Let's try requesting the service "First" on port 80.
$ curl 10.0.1.2;
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment