when I try to execute docker exec container … in terminal, it works fine. but if i use the same command with bash as in yml file it gives an error /bin/bash: line 2: exec: mysql_server_container: not found. Here is the execution log.
mysql_server_container | [Entrypoint] MySQL Docker Image 5.7.21-1.1.4
mysql_server_container | [Entrypoint] Starting MySQL 5.7.21-1.1.4
weather_station_app_1 | /bin/bash: line 2: exec: mysql_server_container: not found
From here, we can see that mysql_server_container is already started before the applicaiton execution.
so, the command you were trying to issue is ‘mysql_server_container’, which doesn’t exist
also,
-h localhost
is not correct, in the weather station you need to talk to the mysql_server_container where the database is…
localhost is inside the weather station container
even I change the host name to container, it didn’t work. Basically, I want to run a MySQL script before I run the java application. Anyways to do that? If I run mysql -uroot -proot ... command in the same container as mysql, then it returns ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) and if I run in the other container, it says mysql not found. Don’t know what is the correct way to do this. but if i run docker exec container_name mysql .... in terminal, it works fine.
I actually tried it this way: command: > /bin/bash -c "/etc/init.d/mysql start; mysql -uroot -proot , which should start mysql server before executing the script. but when executed, bin/bash: /etc/init.d/mysql: No such file or directory