Pipeline docker exec curl - (7) Failed to connect: Connection refused

Hi everyone,

after researching and trying out different things I still have two different errors so I hope someone of you can help me.

I try to execute a curl command inside a running Docker container in my bitbucket pipeline. I wanna check if the node server is running correctly and the login site has a get 200.

 

Parts of my bitbucket-pipelines.yml

options: docker: true
pipelines:
branches:
master:
-
step:
name: build app
caches: - node
script:
-
export IMAGE_NAME_APP=$DOCKER_USER/client:$BITBUCKET_COMMIT
# authenticate with the Docker Hub registry
-
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
# pull docker mongodb image and start it
-
docker pull $DOCKER_USER/mongodb:latest
-
docker pull $DOCKER_USER/client:latest
-
docker run -d -p 27017:27017 --name mongodb -i $DOCKER_USER/mongodb:latest
-
docker ps
-
docker run -d --env-file=docker.env -p 3001:3001 --name client --link mongodb:mongodb -i $DOCKER_USER/client:latest
-
docker ps

- docker exec -i client curl -I 0.0.0.0:3001/signin/ | head -n 1 | grep "HTTP/1.[01] [23].."

 

Both container running and now I wanted to check if the website is running inside the container with a curl statement but It's not working. I tried the same commands locally and it works. I also switched already between IP address like 127.0.0.1 and 0.0.0.0 --> both did not work in the pipeline but locally 

docker ps output:

Bildschirmfoto 2018-01-19 um 11.18.45.png

OutPut in my Pipeline:

Bildschirmfoto 2018-01-19 um 11.20.25.png

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--

0curl: (7) Failed to connect to 0.0.0.0 port 3001: Connection refused

 

try with curl command directly in the shell

I also tried to execute the curl command directly in the pipeline shell but then I also have an error, but a different one:

Bildschirmfoto 2018-01-19 um 11.19.29.pngcurl --head http://127.0.0.1:3001/signin/ | head -n 1 | grep "HTTP/1.[01] [23].." % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (56) Recv failure: Connection reset by peer

 

Maybe someone of you have an idea how to solve that issue. My bitbucket-pipelines.yml is sligthly changed for here and it's also pulling instead of building the image currently to speed up the feedback from the pipeline.

 

Thanks you all so much for reading this and helping me. Wish you all a great day :)

 

1 answer

1 accepted

The solution for running the curl command directly in the container, exchange IP address against localhost :

docker exec -i client curl -I localhost:3001/signin/ | head -n 1 | grep "HTTP/1.[01] [23].."

works now :)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

23,320 views 26 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you