-1

I have taken the latest docker image of mysql but I am unable to connect to it from windows host machine.

Executed the following commands:

 docker run -p 3306:3306 --hostname=sql --name=mysql_working -d mysql/mysql-server:latest

I can see the IP address with the following command:

docker inspect --format "{{ .NetworkSettings.IPAddress }}" 3ddbeeeb27e9enter

When I do telnet, it is timing out

telnet sql 3306

same for ping

ping <ip address from docker>

Can anyone please advise on whats missing?

user3384231
  • 3,641
  • 2
  • 18
  • 27
  • The `docker run -p` option should make the service available on your host's IP address at that port (or, if you're using Docker Toolbox, the `docker-machine ip` address). The `docker inspect` IP address is not useful for many practical purposes and you never need to look it up. – David Maze Jun 28 '19 at 11:26

2 Answers2

0

step1: you need to the changed the default password of MySQL after the first install in docker container

docker logs <container_name or container_id>
docker logs <container_name or container_id> 2>&1 | grep GENERATED

step2:notedown default password

step3:

docker exec -it <container_name or container_id> mysql -uroot -p

Enter default password

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

For more info of step1 to step 3 check here

step4:Add new user in mysql as username root and host any with password

create user 'root'@'%' identified by 'password';

step5:Grant all permission to that user

grant all privileges on *.* to 'root'@'%' with grant option;

For more info of step4 to step 5 check here

step 6: Exit from docker container: press ctrl+p+q keys (not plus key combination of ctrl with p and q)

step7: suppose you are on hostmachine then (else you give ipaddress of hostmachine instead of localhost)

telenet -l root localhost 3306  

It asks for password enter password (we given password as password in step4)

press ctrl+] key (not plus key combination of ctrl with ])

Telent connect successfully ..!!

Mangesh Auti
  • 1,123
  • 1
  • 7
  • 12
0

You are exposing the port 3306 so the Sql container is available to your host.

If you are on Windows machine type ipconfig

Or for Linux:

ifconfig or ip addr to find your host machine's IP Address and use that IP to connect to Sql.

You can also check docker container logs by docker logs -f container_id here -f is for following the logs.

nPcomp
  • 8,637
  • 2
  • 54
  • 49