Internal network between container Docker Compose with outgoing connection

Hi, I am a newbie to Docker.
I am trying to run my application containing from multiple containers

Here is my docker-compose.yml file

version: '3.3'
services:
  php-service:
    container_name: 'php-service'
    build: './php-service'
    networks:
      - backend
    ports:
      - '8666:8666'
  go-service:
    container_name: 'go-service'
    build: './go-service'
    ports:
      - '8825:8825'
      - '8835:8835'
    volumes:
      - './go-service:/go/src/go-service'
    networks:
      - frontend
      - backend
    depends_on:
      - 'mongo'
      - 'consul'
  consul:
    image: 'consul:latest'
    networks:
      - backend
    ports:
      - "8300:8300"
      - "8400:8400"
      - "8500:8500"
      - "8600:53/udp"
  mongo:
    image: 'mongo:latest'
    container_name: 'mongo'
    networks:
      - backend
    ports:
      - '27100:27017'

networks:
  frontend:
    internal: false
  backend:
    internal: true

What I want to achieve.

The Outside World - is a network space of a hosting machine where the Docker daemon is running.

  1. Go-Service, PHP-Service, Consul and Mongo Db communicate over internal network not exposed to the outer world. Let’s call this network backend.

  2. I want services inside backend network to be able to send outgoing requests to outer world

  3. Another network is for the outside world, I need to expose only specific ports. In my case I want to expose 8825 and 8835 only. So that ports will be exposed as localhost:8825 and localhost:8835 on the hosting machine

Is it possible to get the desired configuration?

Or maybe I am doing something wrong, please suggest any other good way to achieve this.

Thank you so much

Only expose the public ports you want, you don’t need the 2 network for your docker env.

You can remove the consul if you want, docker support the routing for you.