Tuesday, February 6, 2024

[SOLVED] Cannot curl to the docker container

Issue

I build the docker image

...
ENV PORT=8080
ENV ADDRESS=0.0.0.0

EXPOSE 8080
CMD ["node", "/usr/app/src"]

I can run it by docker run

[HttpFastifyServer]: Initializing server on address 0.0.0.0:8080
[HttpFastifyServer]: └── (empty root node)
    ├── / (POST)
    │   └── / (POST)
    └── * (OPTIONS)

[Process]: Process initialized

But I cannot curl it.

$ curl -X POST http://0.0.0.0:8080/
curl: (7) Failed to connect to 0.0.0.0 port 8080: Connection rejected
$ curl -X POST http://127.0.0.1:8080/
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection rejected
$ curl -X POST http://localhost:8080/
curl: (7) Failed to connect to localhost port 8080: Connection rejected

I don't see any ip address

$ docker inspect myImage:1.0.0  | grep "IPAddress"
$

Any ideas?


Solution

If you expose port 8080 of your app in the container and you want to access it from the outside on port 8080 as well, you need to add -p 8080:8080 to your docker run command.



Answered By - P.J.Meisch
Answer Checked By - Gilberto Lyons (WPSolving Admin)