0

I want create dockerFile, that will build image, that contains some data_preset, so mysql is not empty;

  1. I create some mysqlDump files and put them in base folder

  2. Make DockerFile

FROM mysql:5.7

RUN mkdir /dbsheme

COPY /base/ /dbsheme

RUN /bin/bash -c "/usr/bin/mysqld_safe --skip-grant-tables &" && \
  sleep 5 && \
  mysql -u root -e "CREATE DATABASE main" && \
  mysql -u root -e "CREATE DATABASE shard1" && \
  mysql -u root -e "CREATE DATABASE docker" && \
  mysql -u root main < /dbsheme/main.db && \
  mysql -u root shard1 < /dbsheme/shard1.db

CMD ["mysqld"]
  1. Build docker image docker build . -t my_custom

  2. Run image docker run --name mysql_with_dump -v db/docker/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pass -d my_custom

  3. Look inside the container and it is default mysql without my tables and dump. What did i wrong with setup?

Sergey Bakotin
  • 283
  • 1
  • 3
  • 12
  • You can't create a derived `mysql` image that contains preloaded data. Instead, you can write those commands in an SQL script that goes in `/docker-entrypoint-initdb.d`, either in an image or bind mounted, and the `mysql` image will run it the first time the container starts up. – David Maze Feb 08 '22 at 10:32

0 Answers0