Home > database >  docker-compose: postgres container not working as posgres already installed in Vitual Machine and be
docker-compose: postgres container not working as posgres already installed in Vitual Machine and be

Time:07-01

I have the following container in my docker-compose file:

services:
#
# Database container
#
db:
    image: postgres:10.0
    environment:
        - POSTGRES_USER=${CTR_DB_USER}
        - POSTGRES_PASSWORD=${CTR_DB_PASSWORD}
        - POSTGRES_DB=${CTR_DB_NAME}
    volumes:
        - postgres10-ctr-data:/var/lib/postgresql/data
    ports:
        - "5432:5432"

If I build the container I get the following error:

Recreating ctr_db_1 ... error

ERROR: for ctr_db_1  Cannot start service db: driver failed programming external connectivity on endpoint ctr_db_1 (9faa39896fede0e32f42a0371450f1a0ed1b8d6104070fd766faa4fb95630f13): Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint ctr_db_1 (9faa39896fede0e32f42a0371450f1a0ed1b8d6104070fd766faa4fb95630f13): Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use
ERROR: Encountered errors while bringing up the project.
make: *** [docker-build-ctr-image-and-restart] Error 1

That is because I have already installed posgres in my Virtual server wit a database used by another app developed by another team. How can i make my container work?

CodePudding user response:

You shouldn't really be running 2 databases on one server, but assuming you have no other option, then the solution is to bind it to another port. For example:

ports:
    - "12345:5432"

However, port 5432 is the default (assigned by IANA and standardized) to be used for PostgreSQL, so changing it will most likely require configuring other stuff. Your biggest concern is that you have two teams with different databases working on the same server. That architecture is something to look over.

  • Related