'Docker react-flask-app_server_1 exited with code 0 / err 111 conn to db
I have this issue when switching from flask to fast api. My docker server wont stay up. I believe it cannot connect to the db. Err. 111. However there are no logs when I use db:3306. It's sucking down my time and I don't know what the heck the problem is.
docker-compose.yml
version: '3.8'
services:
db:
command: '--default-authentication-plugin=mysql_native_password'
environment:
- MYSQL_DATABASE=investing
- MYSQL_ROOT_PASSWORD=777
image: mysql:8.0.28
ports: [3306]
restart: on-failure
volumes:
- "./db/init:/docker-entrypoint-initdb.d"
# healthcheck:
# test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
# client:
# build: client
# ports: [3000]
# restart: always
server:
build: server
ports:
- "5000:5000"
restart: always
depends_on:
- db
volumes:
- ./server:/tmp
- ./server/data:/tmp/data
database.py
from sqlalchemy import create_engine # type: ignore
from sqlalchemy.orm import declarative_base, sessionmaker # type: ignore
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:777@db:3306/investing"
engine = create_engine(SQLALCHEMY_DATABASE_URI)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
