简体   繁体   中英

Docker: curl: (7) Failed to connect to localhost port 9089: Connection refused

I am trying to connect to my IAM server by using:

curl -i -X POST -H "Content-type: application/json" http://localhost:9089/account/list -d '{"jwt": "jwt_token..."}'

and in doing so I get an error as follows:

curl: (7) Failed to connect to localhost port 9089: Connection refused

Any suggestions would be greatly appreciated!

Edit:

 > npm info it worked if it ends with ok npm info using npm@5.3.0 npm
    > info using node@v8.5.0 npm info lifecycle iam@1.0.2~prestart:
    > iam@1.0.2 npm info lifecycle iam@1.0.2~start: iam@1.0.2
    > 
    > > iam@1.0.2 start /usr/src/app
    > > node server.js
    > 
    > HTTP listening on port 9089 HTTPS listening on port 9449

root@Ubuntu1604-001:/home/src/IAM# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
blandry/2           latest              f127789f2de7        4 days ago          544MB
blandry/3           latest              f127789f2de7        4 days ago          544MB

root@Ubuntu1604-001:/home/src/IAM# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                     NAMES
cc28d00d1667        blandry             "npm start"         33 minutes ago      Up 33 minutes       0.0.0.0:32768->9089/tcp   objective_mclean

Dockerfile:

FROM node:8.5.0-wheezy
RUN apt-get update

WORKDIR /usr/src/app
ENV ldap_port 389
ENV http_port 9089

ENV ladp_ip 10.119.226.149
ENV URL  10.119.226.149
ENV authentication eyJhbGciOiJIUz...

COPY package.json package-lock.json /usr/src/app/
COPY . .

EXPOSE 9089
CMD ["npm", "start"]

Try below

curl -i -X POST -H "Content-type: application/json" http://localhost: 32768/account/list -d '{"jwt": "jwt_token..."}'

Your docker ps shows

root@Ubuntu1604-001:/home/src/IAM# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                     NAMES
cc28d00d1667        blandry             "npm start"         33 minutes ago      Up 33 minutes       0.0.0.0:32768->9089/tcp   objective_mclean

That means you didn't map 9089 to 9089 . To do that make sure you run your container as

docker run -p 9089:9089 <image>

If you are trying to do this curl inside a docker you don't need the http prefix. I had this same issue yesterday, and I succeeded when I tried sending curl name_of_container:port/path/to/the/method .

You have mapped 32768 host port with 9089 port of docker.

root@Ubuntu1604-001:/home/src/IAM# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                     NAMES
cc28d00d1667        blandry             "npm start"         33 minutes ago      Up 33 minutes       0.0.0.0:32768->9089/tcp   objective_mclean

Use 32768 port instead of 9089 port.

curl -i -X POST -H "Content-type: application/json" http://localhost:32768/account/list -d '{"jwt": "jwt_token..."}'

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