简体   繁体   中英

Problem with ports in docker-compose file

I am trying to link my api with my webapp but is doesn't seem to work. I have this error

[HPM] Error occurred while trying to proxy request /users/me from localhost:3000 to http://localhost:8080 (ECONNREFUSED) ( https://nodejs.org/api/errors.html#errors_common_system_errors )

When I try to sign in, it doesn't find the users.

Here is the contents of my docker-compose.yml file

 version: '3'
    services:
      api:
        build: ./web3-2019-api
        ports:
        - "8080:8080"
      webapp:
        build: ./web3-2019-webapp
        ports:
        - "3000:3000"
        links:
        - api

Try to connect via docker host api:8080 instead of localhost.

If you connect via localhost from webapp it expects 8080 to be running in webapp docker, but api is another docker and you should connect via api:8080 . Though both are running in same machine they are virtual machines and you should connect via respective docker name within docker network

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM