I have the following yml file:
version: '2'
services:
# another container
db:
build: ./path/to/dockerfile/
environment:
MYSQL_ROOT_PASSWORD: mypassword
MYSQL_DATABASE: database_name
MYSQL_USER: username
MYSQL_PASSWORD: mypassword
volumes:
- ./Dump.sql:/db/Dump.sql:z
- ./Dump_Test.sql:/db/Dump_Test.sql:z
- ./big_fc.sql:/db/big_fc.sql:z
ports:
- "3306:3306"
and this is the Docker file:
FROM mysql:latest
LABEL maintainer "some@email.com"
RUN apt-get update -y
COPY ./solution.txt /temp/solution.txt
WORKDIR /temp
RUN cat solution.txt >> /etc/mysql/conf.d/mysql.cnf
RUN mysql -u username -pmypassword database_name -e "SOURCE /db/Dump.sql;"
However, when I run docker-compose up -d --build
, I am getting the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I have tried this, and this does not work, I am still getting the same error. What I don't understand is that if I omit the last line of the Dockerfile, and run this instead:
docker-compose exec db mysql -u username -pmypassword database_name -e "SOURCE /db/Dump.sql;"
It works properly, but I would like to avoid running this line separately.
Edit: the following is my Dockerfile
FROM mysql:latest
LABEL maintainer "some@email.com"
RUN apt-get update -y
COPY ./solution.txt /temp/solution.txt
WORKDIR /temp
RUN cat solution.txt >> /etc/mysql/conf.d/mysql.cnf
In case you wonder the contents of solution.txt:
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION