简体   繁体   中英

Docker proxy error: Could not proxy request /api/product/B002QYW8LW from localhost:3000 to http://localhost:5000

I am trying to host my app through docker, but got this error:

client_1  | Proxy error: Could not proxy request /api/product/B002QYW8LW from localhost:3000 to http://localhost:5000.
client_1  | See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).

With the below settings, it works for me locally. I searched this through google and it seems to be relevent to the proxy settings. Some people was able to set the proxy as an object, but it gaves me an error saying proxy needs to be a string. That's why I decided to ask this question here again. Can someone please help out?

I have deleted irrelavent stuff in package.json to save space.

package.json for server:

{
  "name": "",
  "version": "",
  "description": "",
  "main": "src/server.js",
  "scripts": {
  },
  "repository": {
  },
  "author": "",
  "license": "",
  "bugs": {
  },
  "homepage": ""
  "dependencies": {},
  "devDependencies": {
  }
}

package.json for client:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
  },
  "scripts": {

  },
  "eslintConfig": {
  },
  "browserslist": {
    "production": [],
    "development": []
  },
  "proxy": "http://localhost:5000"
}

Containers:

CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS                    NAMES
e4b55b165c9a        productfetching_client   "npm start"         24 hours ago        Up 24 hours         0.0.0.0:3000->3000/tcp   productfetching_client_1
10581d34d189        productfetching_server   "node server.js"    24 hours ago        Up 24 hours         0.0.0.0:5000->5000/tcp   productfetching_server_1

Use the container name registered in docker-compose file as said in a comment or http://0.0.0.0:PORT instead which point to the local container network address, instead of localhost or 127.0.0.1 which point to your regular machine 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