Hi, any solution to above error. I trying to run a sql script inside docker container:
FROM ubuntu:16.04
RUN apt-get update
ADD . /mysqldir
WORKDIR /mysqldir
RUN apt-get install -y debconf-utils
RUN pwd
RUN chmod 777 init.sh
RUN ["/bin/bash", "-c","/mysqldir/init.sh"]
RUN apt-get -y install mysql-server
RUN mysql -u root -proot123 < create-dbs.sql
EXPOSE 3306
init.sh
echo satyam
debconf-set-selections <<< 'mysql-server mysql-server/root_password password root123'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root123'
Not really an issue with this image since you are creating your own custom image FROM Ubuntu. The problem is that MySQL server is not running on the RUN line where you try to connect to it with mysql. The only thing running in the container during that RUN is what is on the RUN line.
Since this is more of a general Docker question and not specific to the mysql image, I will close this issue and refer anything further to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
You can do something similar by using the mysql image and dropping the sql file in /docker-entrypoint-initdb.d/. (https://github.com/docker-library/docs/tree/7ef392aa0ca5f3035840e37c09d2a67e22638d21/mysql#initializing-a-fresh-instance)
FROM mysql:5.7
COPY custom.sql /docker-entrypoint-initdb.d/
Most helpful comment
Not really an issue with this image since you are creating your own custom image
FROMUbuntu. The problem is that MySQL server is not running on theRUNline where you try to connect to it withmysql. The only thing running in the container during thatRUNis what is on theRUNline.Since this is more of a general Docker question and not specific to the
mysqlimage, I will close this issue and refer anything further to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.You can do something similar by using the
mysqlimage and dropping the sql file in/docker-entrypoint-initdb.d/. (https://github.com/docker-library/docs/tree/7ef392aa0ca5f3035840e37c09d2a67e22638d21/mysql#initializing-a-fresh-instance)