The architecture of the app I planning to create consist of an React, Python and Firebird component. The React part will serve as front-end, the Python part will be the back-end which communicates with the Firebird DB. The React and Firebird component will run in Docker and has to communicate with a Firebird server, which runs locally on 127.0.0.1.
The current docker-compose file looks like the following:
version: "3.9"
services:
gui:
build:
context: gui
restart: always
ports:
- 80:80
depends_on:
- api
api:
build:
context: api
restart: always
ports:
- 8000:8000
- 3050:3050
volumes:
- C:/Program Files/Firebird/Firebird_2_5/examples/empbuild:/app/api/empbuild:rw
For connecting to the local Firebird server, the following code can be used:
import firebirdsql
conn = firebirdsql.connect(
host='127.0.0.1',
database='...',
port=3050,
user='sysdba',
password='masterkey'
)
So, I need to establish a connection to the local network within the docker container to 127.0.0.1:3050. Currently I'm getting the following error:
ConnectionRefusedError: [Errno 111] Connection refused
Which is due to that the Firebird service is running outside the container and is not mapped to the network of the docker containers. How can I establish this connection by having those two components communicating with the Local Firebird sever?
First, you can't access host from docker container using 127.0.0.1
.
Second, if your Firebird is run on host, you shouldn't expose port 3050 from your api
container. And even if it runs inside api
container, you still shouldn't expose it: use default network created by docker compose, to connect from gui
to api
using introduced DNS record: api
.