title: Cannot ping docker container created with docker-compose
body: <p>I want to create a PostgreSQL cluster composed by a master and two slaves within three containers. I want to do that with docker-compose. Everything works fine but I cannot ping containers from my Mac.</p>
  
  <p>Here the code of my docker-compose.yml. </p>
  
  <p>On Stackoverflow there is this thread <a href="https://stackoverflow.com/questions/39216830/how-could-i-ping-my-docker-container-from-my-host">How could I ping my docker container from my host</a> that address docker standalone and not docker-compose.</p>
  
  <pre><code>version: '3.6'
  
  volumes:
      pgmaster_volume:
      pgslave1_volume:
      pgslave2_volume:
  
  services:
      pgmaster:
          container_name: pgmaster
  
          build:
              context: ../src
              dockerfile: Dockerfile
  
          image: docker-postgresql:latest
  
          environment:
              NODE_NAME: pgmaster # Node name
  
          ports:
              - 5422:5432
  
          volumes:
              - pgmaster_volume:/home/postgres/data
  
          networks:
              cluster:
                  ipv4_address: 10.0.2.31
                  aliases:
                      - pgmaster.domain.com
  
      pgslave1:
          container_name: pgslave1
  
          build:
              context: ../src
              dockerfile: Dockerfile
  
          image: docker-postgresql:latest
  
          environment:
              NODE_NAME: pgslave1 # Node name
  
          ports:
              - 5441:5432
  
          volumes:
              - pgslave1_volume:/home/postgres/data
  
          networks:
              cluster:
                  ipv4_address: 10.0.2.32
                  aliases:
                      - pgslave1.domain.com
      pgslave2:
          container_name: pgslave2
  
          build:
              context: ../src
              dockerfile: Dockerfile
  
          image: docker-postgresql:latest
  
          environment:
              NODE_NAME: pgslave2 # Node name
  
          ports:
              - 5442:5432
  
          volumes:
              - pgslave2_volume:/home/postgres/data
  
          networks:
              cluster:
                  ipv4_address: 10.0.2.33
                  aliases:
                      - pgslave2.domain.com
  
  networks:
    cluster:
      driver: bridge
      ipam:
        config:
          - subnet: 10.0.2.1/24
  </code></pre>
  
  <p>On my Mac, I have a 192.168.0.0 local network. I expect that doing ping 10.0.2.31 I can ping my container but this is not possible. I think this is due to Linux VM created inside Mac where containers live and the IPs are not reachable outside this VM.</p>
  
  <p>Can someone help me to understand how to make the above three IP reachable? IPs are reachable from one container to another.</p>
  
  <p>Here my full code:
  <a href="https://github.com/sasadangelo/docker-postgres" rel="nofollow noreferrer">https://github.com/sasadangelo/docker-postgres</a></p>