0

I am trying to build a new mysql image from an existing one, and then insert some records into the database as part of the build process to create the new image (i.e. new mysql image = old mysql image + extra table records).

I am not able to add an sql file that contains my insert queries to /docker-entrypoint-initdb.d, cause that is not executing the scripts inside that directory (because the starting image already has a /var/lib/mysql dir available?).

I have tried to do something like the following instead:

FROM my.registry/starting-mysql-img:latest

ADD insert-queries.sql /tmp
RUN mysql -u root mydb < /tmp/insert-queries.sql

But I get a

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

What am I doing wrong / is there an alternative way to achieve my I am looking for?

Diana Eftaiha
  • 73
  • 2
  • 7
  • You mostly can't create a database image with prepopulated data (but see the linked "on build time" question for complex workarounds), but if you put the SQL file in `/docker-entrypoint-initdb.d/` it will be automatically run on first startup. – David Maze Dec 29 '22 at 11:29
  • Thanks for those links David. Doesn't exactly fix my issue, cause I was looking for a more straight-forward way – Diana Eftaiha Jan 03 '23 at 23:38

0 Answers0