'My mysql docker container keeps exiting after running exec command

I am using a script that I made to ease things on my docker. The script basically is

docker run -dit -e MYSQL_ROOT_PASSWORD=user123 --name lar -p 3306:3306 mysql:5.7

This one creates a docker container with the name lar.


The other script to create a database in my container is:

echo "Enter database name to create: "
read dbName
mysqlScript="CREATE DATABASE $dbName;"
echo "Running script $mysqlScript"
docker exec -i lar mysql -uroot -puser123 <<< $mysqlScript

They both worked perfectly when I was using them on windows WSL but now there seems to be some trouble. Whenever I try to run the createDB.sh file, the container suddenly stops. Its not only for script file but whenever I try to manually exec into the container, the container goes down.

this is the log

2022-05-01 16:19:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.38-1debian10 started.

And anytime I restart the container and repeat the same process, the same thing happens.


Checked links: How can I run bash in a new container of a docker image?

docker run exited right away?


If anyone wants to check out the actual script files: https://github.com/sugamkarki/docker-scripts/tree/master/mysql



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source