title: can't connect to local postgres from docker container
body: <p>I have some docker containers such as php, nginx, etc. A also have postgres locally because I have learned that dabatase inside docker container is a bad practise. But I can't connect to local postgres from docker container.</p>
  
  <p>At this moment I have done next</p>
  
  <p>In <strong>postgresql.conf</strong> I changed listen_addresses</p>
  
  <pre><code>listen_addresses = '*'
  </code></pre>
  
  <p>In <strong>pg_hba.conf</strong> I have added next line</p>
  
  <pre><code>host    all     all     0.0.0.0/0       md5
  </code></pre>
  
  <p>The I executed next command for iptables</p>
  
  <pre><code>iptables -I INPUT -p tcp -m tcp -s 0.0.0.0 --dport 5432 -j ACCEPT
  </code></pre>
  
  <p>Then I restarted postgres.</p>
  
  <p>My database configuration</p>
  
  <pre><code>DB_CONNECTION=pgsql
  DB_HOST=my_server_ip_address
  DB_PORT=5432
  DB_DATABASE=mydbname
  DB_USERNAME=mydbuser
  DB_PASSWORD=mydbpasswd
  </code></pre>
  
  <p>But i still can't connect to posgresql. At the same moment I can connect to postgres via psql or phpstorm</p>
  
  <p>My docker-compose.yml</p>
  
  <pre><code>version: '3.7'
  
  networks:
    backend-network:
      driver: bridge
    frontend-network:
      driver: bridge
  
  services:
    &amp;app-service app: &amp;app-service-template
      container_name: k4fntr_app
      build:
        context: ./docker/php-fpm
        args:
          UID: ${UID?Use your user ID}
          GID: ${GID?Use your group ID}
          USER: ${USER?Use your user name}
      user: "${UID}:${GID}"
      hostname: *app-service
      volumes:
        - /etc/passwd/:/etc/passwd:ro
        - /etc/group/:/etc/group:ro
        - ./:/var/www/k4fntr
      environment:
        APP_ENV: "${APP_ENV}"
        CONTAINER_ROLE: app
        FPM_PORT: &amp;php-fpm-port 9000
        FPM_USER: "${UID:-1000}"
        FPM_GROUP: "${GID:-1000}"
      networks:
        - backend-network
  
    &amp;queue-service queue:
      &lt;&lt;: *app-service-template
      container_name: k4fntr_queue
      restart: always
      hostname: *queue-service
      depends_on:
        - app
      environment:
        CONTAINER_ROLE: queue
  
    &amp;schedule-service schedule:
      &lt;&lt;: *app-service-template
      container_name: k4fntr_schedule
      restart: always
      hostname: *schedule-service
      depends_on:
        - app
      environment:
        CONTAINER_ROLE: scheduler
  
    &amp;sportlevel-listener sportlevel_listener:
      &lt;&lt;: *app-service-template
      container_name: k4fntr_sl_listener
      restart: always
      hostname: *sportlevel-listener
      ports:
        - "${SPORTLEVEL_LISTEN_PORT}:${SPORTLEVEL_LISTEN_PORT}"
      depends_on:
        - app
      environment:
        CONTAINER_ROLE: sl_listener
  
    &amp;php-fpm-service php-fpm:
      &lt;&lt;: *app-service-template
      container_name: k4fntr_php-fpm
      user: 'root:root'
      restart: always
      hostname: *php-fpm-service
      ports: [*php-fpm-port]
      entrypoint: /fpm-entrypoint.sh
      command: php-fpm --nodaemonize
      networks:
        - backend-network
        - frontend-network
  
    echo-server:
      container_name: k4fntr_echo
      image: oanhnn/laravel-echo-server
      volumes:
       - ./:/app
      environment:
        GENERATE_CONFIG: "false"
      depends_on:
        - app
      ports:
        - "6001:6001"
      networks:
        - backend-network
        - frontend-network
  
    nginx:
      container_name: k4fntr_nginx
      image: nginx
      volumes:
      - ./docker/nginx/config:/etc/nginx/conf.d
      - ./:/var/www/k4fntr
      depends_on:
        - *php-fpm-service
      ports:
        - "${NGINX_LISTEN_PORT}:80"
      networks:
        - frontend-network
  
    redis:
      container_name: k4fntr_redis
      image: redis
      restart: always
      command: redis-server
      volumes:
        - ./docker/redis/config/redis.conf:/usr/local/etc/redis/redis.conf
        - ./docker/redis/redis-data:/data:rw
      ports:
        - "16379:6379"
      networks:
        - backend-network
  </code></pre>