Unable to curl from one container to another

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.

You can access a specific container from another by it’s name. So you can try

curl -i nginx_web:9000

Also exposing the same port that you have mapped with ports is probably something that you don’t want