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

Postgres docker in Pipelines: no server Edited

I'm trying to work with a Postgres container in Pipelines, adding it as service and using `psql`, but it fails for different reasons. Hence I reduced the `bitbucket-pipelines.yml` to the simplest version, but still cannot make it work:

- step:
image: postgres:latest
- psql

This returns the following:

+ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I tried to find a hint among answered questions, here and on Stackoverflow, but nothing seems to work.

I would greatly appreciate if someone could help me understand what am I doing wrong.


UPDATE: Looking at the log, when starting postgres as a service, I noticed this:

PostgreSQL init process complete; ready for start up.
2018-07-09 22:45:16.472 UTC [1] LOG: listening on IPv4 address "", port 5432
2018-07-09 22:45:16.472 UTC [1] LOG: listening on IPv6 address "::", port 5432
2018-07-09 22:45:16.476 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

Is it correct that it's listening on the address ""? I would expect that to be "", according to 

Use services and databases in Bitbucket Pipelines:

These services share a network adapter with your build container and all open their ports on localhost. No port mapping or hostnames are required. For example, if you were using Postgres, your tests just connect to port 5432 on localhost. 

On the other hand, the log is saying that the server is listening on exactly the same Unix socket that the error message is mentioning.

Again, I would really appreciate if someone could help with this.

1 answer

1 accepted

3 votes
Answer accepted

I kind of found the "solution". However, to be honest, I would prefer to have found the answer in the Pipelines documentation and save time.

I don't know the internals of Pipelines, so any comment giving more details and explaining the issue better is totally welcome.

It seems that Postgres in Pipelines is not accessible if defined as a normal image (not as a service). If you define your `bitbucket-pipelines.yml` like this:

- step:
image: postgres:latest
- psql -U postgres -c "\du"

the container doesn't seem to start (judging by the log), and obviously there's no access to the database, because it's not there. It's a bit strange, I would expect to have the image that I define launched and to have access to what's installed on the container.

Conclusion: Postgres docker works in Pipelines only when defined as a service.

When initiated as a service, it is accessible for `psql` commands, but you have to use the remote access format, even when the host is (probably due to linking). When you use `psql` (as opposed to connecting Postgres through a driver, from an application or test), it probably happens from the host machine, hence you need to make sure it has the client installed:

- step:
- apt-get update && apt-get install -y postgresql-client
- psql -h -p 5432 -U postgres -c "\du"
- postgres
services: postgres:
image: postgres

The mapping to localhost is probably done by Pipelines. The standard Postgres container starts the database listening on '', hence replacing '' with '' will work too.

can we use below code to populate postgres database for test runs

1.) docker run -v /tmp/my_scripts:/docker-entrypoint-initdb.d postgres


FROM postgres:9.4
RUN mkdir -p /tmp/psql_data/
COPY db/structure.sql /tmp/psql_data/COPY scripts/ /docker-entrypoint-initdb.d/

Suggest an answer

Log in or Sign up to
This widget could not be displayed.
Community showcase
Posted in Bitbucket

How do you use the Bitbucket-Jira integration? How does it help your team?

Hey everyone, over the past year, we've added several new features on how you can use Bitbucket and Jira together. We'd love to know how you are using the integration and how it's helping your team...

884 views 5 3
Join discussion

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