Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Pipeline – Connection refused to port 80 when using custom docker image

Edited

Hi all,
Here's my problem. I'm using custom docker image based on "php:7.3-apache" in Pipelines. When the pipeline runs I'm getting "Connection refused" when trying to curl / connect to port 80. This does not happen when I use the original "php:7.3-apache" image. What is weird is that the custom image works locally just fine and I'm able connect to port 80. The issue seems to be present only in Pipelines.

Dockerfile

FROM php:7.3-apache
RUN apt-get update && apt-get install -y netcat # Only for debugging purposes
RUN docker-php-ext-install pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Pipeline (snippet):

...
- nc -zv 127.0.0.1 80
- echo "TEST" > /var/www/html/test.html
- curl -v http://127.0.0.1/test.html
...

Response to the above

 nc: connect to localhost (127.0.0.1) port 80 (tcp) failed: Connection refused

Running the image locally

root@b4325d0e00d1:/var/www/html# nc -zv 127.0.0.1 80
Connection to 127.0.0.1 80 port [tcp/*] succeeded!

Any ideas what is the issue and how to get around this?

1 answer

0 votes

@Hannu Pölönen I suppose 80 port can be busy in pipelines, 80 is pretty often used port, for http. Try to expose another port, for example 8000 or 9000 and use it to connect.

Hi @Halyna Berezovska thanks for the tip. Unfortunately changing the port didn't help either. I tried 8080 and 8888 but to no avail.  

@Hannu Pölönen try to go with

nc -zv 0.0.0.0 8080

 Also, I suspect there is something wrong with your network bridge in docker container OR you don't use `services` keyword. I suppose , you just don't create any connection. I have a recipe for you that may suit if don't necessarily need to install anything:

Check out services definitions in bitbucket pipelines https://support.atlassian.com/bitbucket-cloud/docs/databases-and-service-containers/

You may use approach sth like this

definitions: 
  services: 
    my-apache-service: 
      image: php:7.3-apache
      variables: 
        MY_VARIABLE: 'value'
        ...


test: &test
step:
name: Test
script:
- nc ...
services:
- my-apache-service

If you have some custom image , you can push to docker registry first and then use it.

Regards, Galyna

@Hannu Pölönen anyway, if you share your pipeline (just structure , without real names), we could help you to make it work

Thanks for your input @Halyna Berezovska Someone else from Atlassian is also looking into this. If they cannot find the issue, I'll share the pipeline definitions.

I gave this a shot and it indeed seems to work correctly if I create a separate service container for the one running apache. I suppose creating a separate service container for apache is the way to go. 

 

The only thing I don't still quite get is why I would need to create a separate container only when using a custom docker image? 

@Hannu Pölönen because for now I don't know (may be you found the way, however), if there is a possibility for you to use custom image in the services definitions, if you did not push it to your docker registry before.

 

I know that services in their definitions accept docker registry image with tag, and I don't know currenlty, which syntax would be for service definition if you want to run docker container locally in pipeline, without pushing it first.

But if you succeeded, we are happy. If you want - welcome to share how you did it.

Regards, Galyna

Hi @Halyna Berezovska, I did push my custom image to the docker registry before trying to use it in pipelines. It is however a private docker repo so I'm not able to share the image.

I was able to get around the issue for now but it's not really a permanent solution. I will definitely share my final solution / findings once I get back to this project. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

106 views 2 4
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you