I'm running the following bash script via Terraform during the creation of CentOS server.
"sudo docker run -d --restart=unless-stopped --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=${var.mysql_root_password} mysql",
"sudo yum -y install mysql",
"mysql -u root -p${var.mysql_root_password} -h 127.0.0.1"
But the MySQL command fails with the following output
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
However, if I connect via SSH to server, I can run the mysql command and successfully connect to MySQL.
I have shortened the mysql command above to simplify my question. I was trying to use this command to connect to the MySQL instance and create a user and database. I have managed to get that to work by passing the username and database I want to create via environment variables as part of the docker run command. However, I'm interested to know why the above does't work via Terraform but does work when I SSH to the server.
Cheers
Chris