Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker container does now create table on run, MariaDB

I not sure what im doing wrong here but my docker container mariadb does not create a table when it start.

what am i doing wrong?

docker-compose.yml

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

version: '3'
services:
  db:
    build: .
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: checkitDB
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypassword
      MYSQL_ROOT_PASSWORD: rootpassword
    volumes:
      - ./initDB:/docker-entrypoint-initdb.d

initDB.sql

CREATE TABLE checkitDB.tasks (
    id VARCHAR(255) NOT NULL,
    title VARCHAR(32) NOT NULL,
    description TEXT NOT NULL,
    PRIMARY KEY (id)
);

>Solution :

There can be a couple of reasons for this.

Do you have volume mapping for the database as well? The directory ‘docker-entrypoint-initdb.d’ has ‘init’ in it to indicate that the scripts are only run on database initialization. So if you already have a database, the scripts aren’t run.

Another thing is that you map ./initDB but your file is called initDB.sql. If you just want to map the file, you should do

- ./initDB.sql:/docker-entrypoint-initdb.d/initDB.sql
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading