0

I am using docker compose to set up a python app and connect it to Crate DB which is also in a container. Everything works smoothly if I connect with localhost:4200 from my local terminal, but when I add the python script to the container, it cannot reach the DB anymore. This is the docker-compose file:

crate-db:
labels:
  org.fiware: 'myservice'
image: crate:${CRATE_VERSION}
hostname: crate-db
container_name: crate-db
ports:
  # Admin UI
  - "4200:4200"
  # Transport protocol
  - "4300:4300"
  - "5432:5432"
command: crate -Cauth.host_based.enabled=false  -Ccluster.name=democluster -Chttp.cors.enabled=true -Chttp.cors.allow-origin="*"
environment:
  - CRATE_HEAP_SIZE=2g
volumes:
  - crate-db:/data

py-service:
labels:
  org.fiware: 'myservice'
container_name: 'py-service'
build: ./py-service/.
depends_on:
  - crate-db
volumes:
  - .:/py-service
links:
  - 'crate-db'

networks:
labels:
      org.fiware: 'myservice'
  default:
    ipam:
      config:
        - subnet: 172.18.1.0/24

The Python script connects as follows:

from crate import client
connection_device = client.connect("http://localhost:4200/")

I tried basically any combination of localhost, 0.0.0.0, "crate-db", 172.18.1.0, 172.18.1.4 (the crate db endpoint) as hosts and 4200, 4300 and 5432 as ports. The Grafana service which is also in the docker compose connects to the Crate DB on host:"crate-db", port: "5432" (which still does not work).

All fails with error:

raise ConnectionError( crate.client.exceptions.ConnectionError: No more Servers available, exception from last server: HTTPConnectionPool(host='172.18.1.4', port=4200): Max retries exceeded with url: /_sql (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbaf0419460>: Failed to establish a new connection: [Errno 111] Connection refused'))

As mentioned above, when I run the app out of the container it connects simply with localhost:4200. I am probably missing something crucial here so I hope anybody could give me a hand, it would be really appreciated.

FS93
  • 51
  • 4
  • The Compose service name `crate-db` should work as a host name from other containers in the same Compose file. This potentially sounds like the symptom of a service listening only on the container-private localhost interface; do you need to change some configuration on the database to listen on 0.0.0.0? – David Maze Aug 10 '22 at 15:21
  • What can I change on the crate DB configuration in the compose file to achieve what you propose? – FS93 Aug 10 '22 at 17:40

0 Answers0