I am facing a problem when I am trying to connect to mysql using docker.
My docker-compose file
version: '2'
services:
app:
build:
context: ./docker/app
dockerfile: Dockerfile
image: ebdaa-m.test.com/app
volumes:
- .:/var/www/html
ports:
- "80:80"
networks:
- sdnet
node:
build:
context: ./docker/node
dockerfile: Dockerfile
image: ebdaa-m.test.com/node
volumes:
- .:/var/www/html
networks:
- sdnet
mysql:
image: mariadb:10.5
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "ecom"
MYSQL_USER: "root"
MYSQL_PASSWORD: "root"
volumes:
- mysqldata:/var/lib/mysql
networks:
- sdnet
redis:
image: redis:alpine
volumes:
- redisdata:/data
networks:
- sdnet
networks:
sdnet:
driver: "bridge"
volumes:
mysqldata:
driver: "local"
redisdata:
driver: "local"
Now when I compose this the container gets created. My docker ps -a command gives me the following result
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5c925d3610c0 ebdaa-m.test.com/node "node" 2 minutes ago Exited (0) 2 minutes ago ebdaa-m-node-1
d001ed99afa4 mariadb:10.5 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp ebdaa-m-mysql-1
7f86bd9a006c ebdaa-m.test.com/app "/usr/bin/supervisord" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp ebdaa-m-app-1
354b5ae00e39 redis:alpine "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 6379/tcp ebdaa-m-redis-1
Now When I am trying to connect to the mysql using sequel pro. I am passing the following credentials to connect
Host: 127.0.0.1
User: root
Password: root
Port: 3306
I get the following error when I try to establish a connection -:
Lost connection to MySQL server at 'reading initial communication packet', system error: 0 (2013)
Double-check the MySQL host and port settings are correct, the server is running, and that no firewall settings are blocking access to the server.
If you are connecting through an SSH tunnel, the MySQL host should be the correct address relative to the machine you're SSHing into. Using, for example, the external IP for the MySQL host rather than the local one can often be a source of problems.
Please assist. I am not able to understand what could be the issue as it was working fine before.
Thank you in advance.
CodePudding user response:
You claim "it was working fine before". What happened in the meantime?
What you can do as checks is to find out if a process is listening to port 3306:
netstat -lanp | grep :3306
- If the output is empty go back and check your container as nothing is listening on that port.
- If the output contains 127.0.0.1 or "any wildcard of IP" try the connection again
- If the connection contains a specific IP which is not 127.0.0.1, use that IP to connect.
You may also want to check whether the version of mariadb you are running inside the container and the version of the mariadb client outside of the container have compatible versions.