Simulating on and offline networks with Docker Compose

I need to simulate an infrastructure design as per the below image.

I need container1/2/3 to have no internet access, but I want container4 to have access. A pots on SO suggests there is an internet and no-internet flag, but I cant seem to find anything in the Docker Compose docs. Could someone kindly share an example docker-compose.yml for this scenario, or point me to some documentation?

Thanks in advance

If you do not expose the port using ports then no one can access it outside the container.

If you want it to prevent accessing the Internet altogether you can set the internal value of network

1 Like

Great! The docs aren’t great about internal, so I must have brushed over them. This worked for me:

version: '3'

services:
  pinger:
    image: centos:7
    command: ping google.com
    networks: 
      noinet: {}

networks: 
  noinet:
    internal: true