I searched for a long time, a lot of answers, nothing helps ... There is the following docker-compose.yml

 version: '2' services: nginx: build: ./docker/nginx depends_on: - php7 - db volumes: - ./app:/var/www ports: - "8080:80" php7: build: ./docker/php7 ports: - "9000" volumes: - ./app:/var/www working_dir: /var/www environment: XDEBUG_CONFIG: remote_host=192.168.50.75 #Подставить свой удаленный IP PHP_IDE_CONFIG: "serverName=docker" MYSQL_DATABASE: test200 MYSQL_ROOT_PASSWORD: root db: container_name: test200 build: ./docker/mysql ports: - "3306:3306" environment: MYSQL_DATABASE: test200 MYSQL_ROOT_PASSWORD: root volumes: - ./docker/mysql/mysql-data:/var/lib/mysql - ./docker/mysql/dumps:/docker-entrypoint-initdb.d 

There is one line in the mysql dockfile: FROM mysql:latest

in the dumps folder that is linked to the container is a simple sql file:

 create database test; use test; CREATE TABLE testtab ( id INTEGER AUTO_INCREMENT, name TEXT, PRIMARY KEY (id) ) COMMENT='this is my test table'; 

In general, the problem is that after running docker-compose up -d --build new test database docker-compose up -d --build not be created with a test table ... Before each check, it would delete the collected docker-compose rm -f containers docker-compose rm -f . I ask for help

Upd: Here is the link to the dock of this feature https://hub.docker.com/_/mysql/ (closer to the bottom of the page is the subtitle Initializing a fresh instance )

  • and command tried? - Senior Pomidor
  • Of course, this is unusual, but you tried to register ./docker/mysql/dumps/mysql.sql:/docker-entrypoint-initdb.d/mysql.sql ? - Senior Pomidor
  • Checked - does not work ( - Oleg Shleif
  • In some difficulties with raising MySQL (you should have more than one process running), it is very difficult to do, and I recommend to abandon this idea. Alternatively, you can start a regular container, fill in a dump with the usual means, then stop and make a commit, but through a regular Dockerfile it is impossible to do this without wasting a huge amount of human resources. - etki
  • one
    Specifically, with "after running docker-compose up -d --build does not create," the case is most likely that / var / lib / mysql already exists, therefore the entrypoint does not attempt to initialize the database again. - etki

0