Docker 1.9.1 - ERROR 2005 (HY000): Unknown MySQL server host - mysql

We have a two docker setup, one is running a django app and the other running MySQL. Earlier we were using docker 1.8.3 and everything was working fine, after upgrading to 1.9.1 we are facing this issue.
We are creating a MySQL docker:
docker run --name <mysql docker name> -e MYSQL_ROOT_PASSWORD={} -d mysql:5.5.44
Next we are running a batchfile, which is nothing but creating a DB, granting access to the user
docker run -it --rm -v <setup_file>:/mnt mysql:5.5.44 sh -c 'exec mysql -h"<db server name>" -P"3306" -uroot -p"<password>" < /mnt/batchfile'
Next we are creating the django docker
docker run --name <django server name> --link <db server name> -it --rm ubuntu /bin/bash
When the django docker comes up we get the error message
ERROR 2005 (HY000): Unknown MySQL server host <DB server> (0)
Is there any additional parameter that we need to send for docker 1.9.1?

Related

How can I to connect to a Docker running mysql?

The instructions here: https://hub.docker.com/_/mysql indicate to run
$ docker run -it --network some-network --rm mysql mysql -hsome-mysql-container -uexample-user -p
But i have no idea what some-network is? So i run this instead and get and 'unknown MySQL host' error even though some-mysql-container is definitely the name of my container.
$ docker run -it--rm mysql mysql -hsome-mysql-container -uexample-user -p
What am I doing wrong here?
'some-network' refers to a docker-network. You need to create it first. I named it 'mysql-network' to make its purpose a bit more clear:
docker network create mysql-network
Then, start database container:
docker run --network mysql-network --name mysql-db -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
Then, start a the client container to connect to the first one:
docker run -it --network mysql-network --rm mysql mysql -hmysql-db -uroot -p
By adding both containers to the same network, they are able to communicate with each other.

Docker container not able to connect to mysql running on host

I have a docker container up and running. When I log in to the container and try to connect to MySQL using python SQL connector I am not able to connect. I am trying to connect using the internal IP after changing the bind-address properties of running MySQL on the host system.
Error
mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on '****' (113)
Count2.py
import mysql.connector
cnx = mysql.connector.connect(user='root', password='root',
host='172.31.37.139',port=3306,
database='test')
Docker command
sudo docker run -it -d -p 4040:4040 -v $(pwd)/count2.py:/count2.py d9e1d42543f9 bin/spark-submit --jars /usr/spark-2.4.1/mysql-connector-java-5.1.49/mysql-connector-java-5.1.49.jar --class com.mysql.jdbc.Driver /count2.py
Can someone help me here?
sudo docker run --network="host" -it -d -p 4040:4040 -d -v $(pwd)/count.py:/count.py d9e1d42543f9 bin/spark-submit --jars /usr/spark-2.4.1/mysql-connector-java-5.1.49/mysql-connector-java-5.1.49.jar --class com.mysql.jdbc.Driver /count.py
Just adding the new host tag worked for me

Unable to connect to MYSQL from Docker Instance

I'm new to Docker and pulled the mysql from the docker hub using following command
docker pull mysql
Now, started mysql instance using following commands.
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql/mysql-server:latest
Unable to find image 'mysql/mysql-server:latest' locally
latest: Pulling from mysql/mysql-server
e64f6e679e1a: Pull complete
799d60100a25: Pull complete
85ce9d0534d0: Pull complete
d3565df0a804: Pull complete
Digest: sha256:59a5854dca16488305aee60c8dea4d88b68d816aee627de022b19d9bead48d04
Status: Downloaded newer image for mysql/mysql-server:latest
1be4f5dde2fb4e1d99e23ee2de5e3b663c7c2d0fabe7ef459cf87385071a2e0d
Now, I've checked what all services are up and running.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1be4f5dde2fb mysql/mysql-server:latest "/entrypoint.sh mysql" 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
e7d9e3713f5c ubuntu "/bin/bash" 6 days ago Up 6 days angry_hodgkin
and now I execute the following commands and unable to connect to mysql -
mysql -h127.0.0.1 -ppassword -uroot
-bash: mysql: command not found
Docker version..
docker --version
Docker version 1.12.3, build 6b644ec
Now, I'm getting below erro - EDIT-1
docker exec -it 1be4f5dde2fb bash
bash-4.2# mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
bash-4.2# sudo mysql
bash: sudo: command not found
https://hub.docker.com/r/mysql/mysql-server/
Get in the docker container using the following command
docker exec -it mysql bash
You can then easily connect to MySQL, by executing the following command
mysql -uroot -p
If you are trying to connect from the host machine, then you will have to install the mysql client.
On mac, the command is as follows
brew install mysql

Connecting to Dockerized MySQL from remote client

tl;dr: database used to be connectable from remote, but after dockerizing it, it isn't (though i can access from host).
I've set up a docker container running MySQL in an ec2 instance, using the following command:
sudo docker run --name mysql-csm -p 3306:3306 -v /db/mysql:/var/lib/mysql -v /db/mysql-config:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=password -d mysql
where: -v /db/mysql:/var/lib/mysql maps my host's database to the docker
and
-v /db/mysql-config:/etc/mysql/conf.d maps my host custom config file to the dockerized MySQL config. the host file is supposed to take precedent, and my custom config contains one line:
[mysqld]
bind-address = 0.0.0.0
I am able to connect to the database via host command-line using the following:
sudo docker run -it --link mysql-csm:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -u"user" -p"pw"'
From the MySQL command-line, all of the tables, etc., are present & look good. This database ran in a regular MySQL version previously, and I could connect remotely.
However, when trying to connect from my laptop using MySQL Workbench, I receive the error:
Table 'performance_schema.session_variables' doesn't exist
Googling suggests it's something to do with upgrading, but I'm not sure how to address that.
ETA: I get the same error when trying to login thru SSH -> TCP/IP via MySQL Workbench.

docker 1.7 multiple port mapping at run failure

Background:
Ubuntu 14.04 LTS - Docker 1.7 - Virtual Interface with its own IP specfically for use with Docker.
Running Wordpress Latest with linked MySQL 5.7 each with their own data containers.
I need to map ports 80 & 443 to the Wordpress container to enforce SSL site wide.
This run string works perfectly:
docker run --name Web --link db-server:mysql -d -e WORDPRESS_DB_NAME=WP -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=somepassword -p 172.31.25.94:80:80 --volumes-from wp-data wordpress
When I run this string I get an error:
docker run --name Web --link db-server:mysql -d -e WORDPRESS_DB_NAME=WP -e WORDPRESS_DB_USER=admin -e WORDPRESS_DB_PASSWORD=somepassword -p 172.31.25.94:80:80 —p 172.31.25.94:443:443 volumes-from wp-data wordpress:latest
Error message:
Unable to find image '—p:latest' locally
Invalid repository name (—p), only [a-z0-9-_.] are allowed
I have read the Docker documentation and Googled for this issue and from everything I have found this should work. Is there something I am missing or is this not possible in 1.7?