0

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

12
  • 1
    "This one creates a docker image with the name lar." - It creates a container with name lar. Commented May 1, 2022 at 16:29
  • 1
    Can you check the line endings of the files (especially the .sh file)? They should be set to linux line endings (lf). Commented May 1, 2022 at 16:32
  • I ran file mysql.sh and I got mysql.sh: Bourne-Again shell script, ASCII text executable. I am not sure if that was what you were asking Commented May 1, 2022 at 16:37
  • No, not really. Can you try opening the file in nano or vi? If you see something like ^M at the end of each line, then the problem is most probably related to line ending encoding. Commented May 1, 2022 at 16:38
  • Oh there are no any ^M thingies. When I was on widows, I had the bad interpreter issue and had used dos2unix to fix it. When that happened, the file totally refused to run but now the container is running and I can see it in the docker ps. Commented May 1, 2022 at 16:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.