0

I need to execute some script in a mysql image and need to create a new image out of it.

FROM mysql:5.7.29
COPY ./multicore.sql /bin
ENV MYSQL_ROOT_PASSWORD=root
RUN /bin/bash -c "mysql -uroot -proot \
    && source > /bin/sample.sql"

So when i execute this Dockerfile i'm getting the following error. The sample.sql run perfectly fine. The error i'm getting is

Sending build context to Docker daemon  116.7kB
Step 1/4 : FROM mysql:5.7.29
 ---> 84164b03fa2e
Step 2/4 : COPY ./multicore.sql /bin
 ---> 54738bfd2ce2
Step 3/4 : ENV MYSQL_ROOT_PASSWORD=root
 ---> Running in 0efc6d84aedb
Removing intermediate container 0efc6d84aedb
 ---> aab5ba5fb5a4
Step 4/4 : RUN /bin/bash -c "mysql -uroot -proot     && source > /bin/sample.sql"
 ---> Running in 526d17218da3
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
The command '/bin/sh -c /bin/bash -c "mysql -uroot -proot     && source > /bin/sample.sql"' returned a non-zero code: 1
sandeep P
  • 67
  • 10

1 Answers1

2

I found two problems. First, you did not start the database when you performed the import. You need to start the database service before you can execute the MySQL import instruction.

I didn't find the /bin/sample.sql file. You need to add the SQL file to the image

Qi Yin
  • 209
  • 1
  • 2