dathere / datapusher-plus-docker

MIT License
10 stars 4 forks source link

Can't connect to postgres inside custom docker network. #6

Open uliss3s opened 1 year ago

uliss3s commented 1 year ago

I have a ckan docker compose setup running on a specific docker network. Ex.: ckan_network

I changed the docker-compose.yml from the datapusher-plus-docker to use this network and updated the env variables accordingly.

version: "3"

volumes:
  pg_data:

services:
  datapusher:
    container_name: datapusher-plus
    build:
      context: ./datapusher-plus/0.11.0/
      dockerfile: Dockerfile
#    network_mode: "host"
    networks:
      - ckan_network
#    ports:
#      - "8800:8800"
    restart: unless-stopped
    environment:
      - SQLALCHEMY_DATABASE_URI=postgresql://datapusher_jobs:*****@db:5432/datapusher_jobs
      - WRITE_ENGINE_URL=postgresql://datapusher:*****@db:5432/datastore

networks:
  ckan_network:
    external: true

db is the postgres instance. Running some commands inside de datapusher container:

But the datapusher-plus container throw errors trying to connect to "localhost".

Error

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
datapusher-plus  |  Is the server running on that host and accepting TCP/IP connections?
datapusher-plus  | connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address
datapusher-plus  |  Is the server running on that host and accepting TCP/IP connections?
uliss3s commented 1 year ago

I think that the docker compose envs SQLALCHEMY_DATABASE_URI and WRITE_ENGINE_URL are being ignored.

Added a volume bind to an external .env file and now it connected as expected.

jqnatividad commented 1 year ago

Hi @uliss3s , do you mind making a PR with your changes?

uliss3s commented 1 year ago

Hi @uliss3s , do you mind making a PR with your changes?

This is not needed anymore. I just pulled the last changes from the project and it's working fine.

uliss3s commented 1 year ago

Hi @uliss3s , do you mind making a PR with your changes?

This is not needed anymore. I just pulled the last changes from the project and it's working fine.

Fake news. I just forgot to remove the volume bind in the docker-compose.yml.

The version 0.14.1 still ignores the envs variables SQLALCHEMY_DATABASE_URI and WRITE_ENGINE_URL.

To work i need to bind the .env file from the host to the container:

  volumes:
    - ./config/.env:/etc/ckan/datapusher/.env:ro