Unable to curl from one container to another

Viewed 12555

I have two containers in one docker-compose.yml. Both are on same on same network. I have added the dependency using "depends_on", I am able to ping the other container, but curl is not working.

version: "2.1"
services:
    web:
            restart: always
            build:
                    context: .
                    dockerfile: web.dockerfile
            ports:
                    - "9000:8080"
            expose:
                    - "8080"

            networks:
                    - test

    nginx_web:
            restart: always
            build:
                    context: .
                    dockerfile: nginx_web.dockerfile
            ports:
                    - "8100:80"
            expose:
                    - "80"
            depends_on:
                    - web
            networks:
                    - test
    networks:
            test:

When I am trying ping from nginx_web container to web, it is working fine. But the curl isn't working. I am getting

curl: (7) Failed to connect to 172.28.0.7 port 8080: Connection refused

And when I am doing curl from the host machine directly to web at port 9000, it is working fine.

2 Answers

I had the same issue, and I had success when I tried to make the curl without http . You should try doing curl name_of_container:8080/path/to/web/method . That worked for me because inside the docker compose, it doesn't need SSL.

Related