我有一个网络:码头工人。从一个容器连接到另一个容器与MySQL
docker network create -d bridge --subnet 172.25.0.0/16 container_network
我有mysql的运行一个容器。运行命令:
docker run -tid -p 3306:3306 --name container_mysql --network container_network container_mysql
而且一个与代码容器:
docker run -tid -v $(pwd):/code -p 5000:5000 --name container_code --network container_network container_code
我想从我的容器访问MySQL数据库的代码,但没有任何工程:
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
第一个命令给me:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Ot她的:
ERROR 2003 (HY000): Can't connect to MySQL server on <host> (111)
任何想法如何实现目标?
编辑1 Dockerfile对于MySQL容器:
所有的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
您是否尝试过使用docker-compose? – Manuel
是的。在我看来,连接一切都有更多的麻烦。 – Snobby