I have a network:
docker network create -d bridge --subnet 172.25.0.0/16 container_network
I have one container with mysql running. Run command:
docker run -tid -p 3306:3306 --name container_mysql --network container_network container_mysql
And one container with code:
docker run -tid -v $(pwd):/code -p 5000:5000 --name container_code --network container_network container_code
I am trying to access mysql DB from my container with code, but nothing works:
mysql -h 172.17.0.1 -P 3306 -u root -p
mysql -h container_mysql -P 3306 -u root -p
mysql -h 127.0.0.1 -P 3306 -u root -p
mysql -h 0.0.0.0 -P 3306 -u root -p
First command gives me:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Others:
ERROR 2003 (HY000): Can't connect to MySQL server on <host> (111)
Any ideas how to achieve the goal?
Edit 1 Dockerfile for Mysql container:
FROM ubuntu:16.04
RUN apt-get update
RUN echo "mysql-server mysql-server/root_password password 1234" | debconf-set-selections
RUN echo "mysql-server mysql-server/root_password_again password 1234" | debconf-set-selections
RUN apt-get install mysql-server -y