Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation Error while connecting flask app to mysql #16

Open
Bilal05476 opened this issue Oct 7, 2023 · 4 comments
Open

Operation Error while connecting flask app to mysql #16

Bilal05476 opened this issue Oct 7, 2023 · 4 comments

Comments

@Bilal05476
Copy link

Bilal05476 commented Oct 7, 2023

OperationalError
MySQLdb.OperationalError: (2002, "Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)")

Screenshot from 2023-10-07 17-08-11

Both containers in same network but above error persist

@sitchatt
Copy link
Contributor

Hi, can you tell me more about your other configuration too? What is the MySQL port you selected?

@Sudarshankevat
Copy link

Hi, can you tell me more about your other configuration too? What is the MySQL port you selected?
port no : 3306

@pratiksha-design261
Copy link

Use the below code for docker-compose.yml it will fix above error :
version: '3.9'
services:

flask-app:
container_name: 'flask-python-application'
build:
context: .
ports:
- '5000:5000'
environment:
MYSQL_HOST: 'mysql-db'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'root'
MYSQL_DB: 'devops'
depends_on:
mysql-db:
condition: service_healthy

mysql-db:
container_name: 'mysql-db'
image: 'mysql:5.7'
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'devops'
volumes:
- type: volume
source: mysql-volume-data
target: /var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 3

volumes:
mysql-volume-data:

@Iam-Tej23
Copy link

please use mysql ip in two-tier-app-deployment.yaml file so that it work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants