How to access host machine port from docker container? [duplicate]

This question already has an answer here:

How to access host machine port from docker container (web)?

My docker-compose.yml file:

version: '3'

services:
  db:
    image: postgres
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: postgres
  web:
    build: .
    command: python server.py
    volumes:
      - .:/code
    ports:
      - 5000:5000
    depends_on:
      - db

Source: StackOverflow