JustSayBegi
JustSayBegi

Reputation: 21

How to resolve "curl: (7) Failed to connect to localhost port 5001: Connection refused" in crontab?

I'm trying to get some json data from my API. My API is running in docker container. When I want to see this data, I just go to the http://localhost:5001/v1/executions endpoint and I can view my data as shown in the image below:

This is my API's end point

But send a request from a crontab file to this end point, I get some errors. You can see the contents of the crontab file from the image below.

* * * * * curl -X GET -d '{"message":}' http:// 127.0.0.1:5001/v1/machines >> /var/log/cron.log 2>&1

This is the content of the crontab file

When I run my containers and this cron I get "Connection refused" error. You can see the error as shown in the image below.

This is the error image

How can I solve this problem? Thanks.

Upvotes: 2

Views: 11114

Answers (1)

stefano manzi
stefano manzi

Reputation: 123

You have to use internal docker ip instead of localhost in your curl command. Try to use docker inspect <container-id> command to find the ip address of your local network.

Upvotes: 2

Related Questions