Mysql: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Created on 20 Sep 2017  路  1Comment  路  Source: docker-library/mysql

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

CMD /docker-entrypoint-initdb.d/setup.sh

EXPOSE 3306

init.sh

!/bin/bash

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'

Most helpful comment

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/

>All comments

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/
Was this page helpful?
0 / 5 - 0 ratings

Related issues

AdriVanHoudt picture AdriVanHoudt  路  4Comments

perfeyhe picture perfeyhe  路  4Comments

tomnewport picture tomnewport  路  3Comments

odero picture odero  路  3Comments

jdoose picture jdoose  路  5Comments