2

I want to connect mysoft docker container to postgresql docker container. But i have some errors:

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

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

here is my docker-compose.yml

version: '2'
services:
  mysoft:
    image: mysoft/mysoft:1.2.3
    ports:
      - "80:8080"  
    environment:
      - DATABASE_URL=postgres://mysoft:PASSWORD@db/mysoft?sslmode=disable
  db:
    image: postgresql
    environment:
      - POSTGRES_USER=mysoft
      - POSTGRES_PASSWORD=PASSWORD
      - POSTGRES_DB=mysoft
    ports:
      - 5432:5432

I want use another, already running docker pg server to connect new soft, also one pg docker server, for more projects Is it possible?

0

2 Answers 2

1

You should add links to the definition of mysoft service in docker-compose.yml. Then your db service will be accessible from mysoft container.

After that your service definition will look like this.

mysoft:
  image: mysoft/mysoft:1.2.3
  ports:
    - "80:8080"  
  environment:
    - DATABASE_URL=postgres://mysoft:PASSWORD@db/mysoft?sslmode=disable
  links:
    - db

Now about error of binding. Probably, you receive it, because you have a local postgresql running on port 5432 or you already have a running docker container with 5432 port mapped to local machine.

ports:
  - 5432:5432

It is used for mapping ports to your local machine. And if you don't need to access container's db from it, just remove it.

I want use another, already running docker pg server to connect new soft, also one pg docker server, for more projects Is it possible?

Yes, it's possible. Use external_links.

If you choose this option:

  1. Remove the db service and links in mysoft service definition from your docker-compose.yml

  2. Add external_links with correct container name to mysoft service definition.

  3. Update host and port in DATABASE_URL according to the container name and postgresql port in it.

Sign up to request clarification or add additional context in comments.

Comments

0

You might want to check of you already have a local postgres running on port 5432? If you do you can not do the ports 5432:5432 but have to expose the inner port to an other outer port e.g. 5555:5432

at least if you are using native docker (running on localhost)...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.