I'm unable to connect remotely from my local machine, everything worked well but suddenly it won't let me to the mysql database anymore. I tried every possible combinations, but none of them worked for me.
I have my PC and Laptop running Windows 10/11 with WSL2 (Ubuntu 22.04). I have a droplet (VPS) at Digitalocean running Ubuntu with Docker. There are 3 different docker containers spinning up (server, database and client). They can communicate with each other without any problem.
When I want to connect from my Laptop (Win 11 WSL2) to the docker "database" container running mysql, it won't work. Ports are open and exposed to the host.
It works only when I connect from my PC with Datagrip software, which was configured before it got messed up, but somehow it still works and allows me to connect to the database. It means it's configured correctly, but I'm unable to connect from other machine.
Is there anything I'm missing ?
Here is my docker-compose.yml
:
version: '3.9'
services:
api:
build:
context: .
dockerfile: Dockerfile
container_name: api
restart: on-failure
env_file: .env
environment:
- DB_HOST=mysql
volumes:
- .:/app
ports:
- ${APP_PORT}:${APP_PORT}
- ${WSS_PORT}:${WSS_PORT}
depends_on:
- mysql
networks:
- appnet
cpus: 0.4
mem_reservation: '512M'
mem_limit: '1152M'
mysql:
image: mysql:8.0
container_name: mysql
command: mysqld --default-authentication-plugin=caching_sha2_password
restart: always
env_file: .env
environment:
- MYSQL_ROOT_HOST=%
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_NAME}
- MYSQL_USER=${DB_USERNAME}
- MYSQL_PASSWORD=${DB_PASSWORD}
volumes:
- mysql-data:/var/lib/mysql
ports:
- ${DB_PORT}:${DB_PORT}
networks:
- appnet
cpus: 0.4
mem_reservation: '256M'
mem_limit: '512M'
networks:
appnet:
volumes:
mysql-data: