Pipeline ? Connection refused to port 80 when using custom docker image
Asked by Hannu P?l?nen:

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?


Answers:
author: Halyna Berezovska
body: [@Hannu P?l?nen](/t5/user/viewprofilepage/user-id/4329468) 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.

comments: author: Hannu P?l?nen
body: Hi [@Halyna Berezovska](/t5/user/viewprofilepage/user-id/3865505) thanks for the tip. Unfortunately changing the port didn't help either. I tried 8080 and 8888 but to no avail.


author: Halyna Berezovska
body: [@Hannu P?l?nen](/t5/user/viewprofilepage/user-id/4329468) 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


author: Halyna Berezovska
body: [@Hannu P?l?nen](/t5/user/viewprofilepage/user-id/4329468) anyway, if you share your pipeline (just structure , without real names), we could help you to make it work


author: Hannu P?l?nen
body: Thanks for your input [@Halyna Berezovska](/t5/user/viewprofilepage/user-id/3865505) Someone else from Atlassian is also looking into this. If they cannot find the issue, I'll share the pipeline definitions.


author: Hannu P?l?nen
body: 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?


author: Halyna Berezovska
body: [@Hannu P?l?nen](/t5/user/viewprofilepage/user-id/4329468) 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


author: Hannu P?l?nen
body: Hi [@Halyna Berezovska](/t5/user/viewprofilepage/user-id/3865505), 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.


author: Halyna Berezovska
body: [@Hannu P?l?nen](/t5/user/viewprofilepage/user-id/4329468) you can also use private image as definition [https://support.atlassian.com/bitbucket-cloud/docs/databases-and-service-containers/#\[hardBreak\]Use-a-private-image](https://support.atlassian.com/bitbucket-cloud/docs/databases-and-service-containers/#[hardBreak]Use-a-private-image)

If you have aws ecr image, then you can also use ecr uri with aws credentials

<https://support.atlassian.com/bitbucket-cloud/docs/use-docker-images-as-build-environments/#Private-images-hosted-by-AWS-ECR--EC2-Container-Registry->


Tags: bitbucket-pipelines