I have a streamlit app that requires connection to MariaDB. When I run docker-compose up I get this error:
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 99] Cannot assign requested address)")
I have a static IP where my app is hosted and an IP address for MariaDB and I am supposed to have access in this way.
This is my docker-compose.yaml file:
services:
app:
restart: always
build: ./app
ports:
- "8501:8501"
command: streamlit run Main.py
mariadb:
image: mariadb:10.5.17
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql
- db_conf:/etc/mysql/conf.d
environment:
MARIADB_ROOT_PASSWORD: Ap$im
MARIADB_HOST: xxx.xx.xxx.xx (IP address of MARIADB)
MARIADB_DATABASE: a
MARIADB_USER: b
MARIADB_PASSWORD: c
networks:
- streamlit_network
nginx:
restart: always
build: ./nginx
ports:
- "80:80"
depends_on:
- app
- mariadb
volumes:
db_data:
db_conf:
networks:
streamlit_network:
external: true
And the python file accessing it:
conn = pymysql.connect(
host=os.environ.get("host"),
user=os.environ.get("user"),
password=os.environ.get("password"),
database=os.environ.get("database"),
cursorclass=pymysql.cursors.DictCursor
The .env file:
# Environment variables defined inside a .env file
host="mariadb"
user="b"
password="c"
database="a"
port="3306"
Any help would be much appreciated. Thank you in advance.