compose icon indicating copy to clipboard operation
compose copied to clipboard

Cannot reach the server IP address from container

Open Reechee88 opened this issue 8 years ago • 10 comments

Hi,

I am running several containers and from one of them I try to reach the server, where the whole system is deployed. Issue:

  • Container X is the container who try to reach 1.2.3.4 ip address (ip address where Container X is running) with curl -> timeout
  • Container X is the container who try to reach 5.6.7.8 ip address (random ip) -> curl successful
  • Container X can reach everything, but the self running Container X

I have no idea what's going on. When I run this compose file from local, I can reach the server. Problem only occurs, when it try to reach itself.

Please help me. Richard

Reechee88 avatar Jan 10 '18 20:01 Reechee88

Hi @Reechee88 !

So in other words, you're trying to reach container X from inside container X using its host facing IP? That's unlikely to work because containers started by Compose are part of an isolated network. You might want to read up on container networking in Compose, and in Docker in general.

If after that you still have questions, please head to the forums where people will be able to help you out with specifics.

shin- avatar Jan 10 '18 23:01 shin-

Hi,

thanks for your kind response. I understand and I know this network separation, which is fine. But in this case, I wouldn't be able to reach e.g. google.com inside Container X. I am able to reach every site, but the hosting machine. It is very weird for me.

I have used the compose configuration, dns. (dns. 8.8.8.8)

Reechee88 avatar Jan 11 '18 07:01 Reechee88

It's probably easier if you share your Compose file.

shin- avatar Jan 11 '18 07:01 shin-

of course. Frontend is the Container X

version: "3.3"

services:
  proxy:
      image: nginx
      container_name: melodiak.proxy
      ports:
        - "80:80"
      volumes: 
        - "./apidoc:/apidoc/api/documentation"
        - "./proxy/default.conf:/etc/nginx/conf.d/default.conf"
        - "./proxy/logs:/var/log/nginx"
        - "./mentorprogram/jatek/dist:/mentorprogram/jatek"
      restart: always
      depends_on: 
        - backend
  workdata:
    image: mongoclient/mongoclient
    container_name: melodiak.workdata
    ports:
      - "4000:3000"
    restart: always
  frontend:
    build: frontend
    container_name: melodiak.frontend
    dns: 8.8.8.8
    volumes:
      - ./frontend/app:/app
    ports:
      - "8000:3000"
    restart: always
    depends_on:
      - backend
  blog:
    build: blog
    container_name: melodiak.blog
    ports:
      - "9900:3000"
    restart: always
    depends_on:
      - workdata
  backend:
    build: backend
    container_name: melodiak.backend
    volumes: 
      - "./backend:/app"
    restart: always
    depends_on:
      - workdata

Reechee88 avatar Jan 11 '18 08:01 Reechee88

Can you explain again in detail what it is you're trying to do? Your Compose file looks fine as far as I can tell.

shin- avatar Jan 11 '18 09:01 shin-

Of course.

Frontend container makes API calls to 1.2.3.4 ip address, which is the ip address of the hosting machine. So this call is an outside call. (This is by server side rendering, I wont dig into details).

Machine: 1.2.3.4 hosts every container, Frontend too Frontend makes API call to 1.2.3.4/api/nice_cats Nginx container forwards there requests to backend. (in every other cases, it works) Timeout -> Frontend cannot reach 1.2.3.4 Frontend can reach google.com, facebook.com, 5.6.7.8, etc. Every other address, expect its own

Reechee88 avatar Jan 11 '18 09:01 Reechee88

Is your machine firewalled by any chance? Are you able to reach 1.2.3.4/api/nice_cats from your browser, or with curl?

shin- avatar Jan 11 '18 19:01 shin-

I can reach it from everywhere, but not from the container.

Reechee88 avatar Jan 11 '18 20:01 Reechee88

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 09 '19 23:10 stale[bot]

This issue has been automatically closed because it had not recent activity during the stale period.

stale[bot] avatar Oct 17 '19 00:10 stale[bot]