I want to create a MySQL container with an initial database and its tables, from a Dockerfile.
I also have a specific /etc/mysql/mysql.conf.d/mysqld.cnf
file (I can simply use ADD
directive in Dockerfile.)
I want my Dockerfile to create a MySQL image with a database named, for example, DBNAME and with the following tables:
CREATE TABLE utente (
ID int NOT NULL AUTO_INCREMENT,
nome VARCHAR(255),
cognome VARCHAR(255),
username VARCHAR(255),
password VARCHAR(255),
PRIMARY KEY (ID)
);
CREATE TABLE sdplines (
ID int NOT NULL AUTO_INCREMENT,
value VARCHAR(255),
session_id VARCHAR(255),
u_id int,
PRIMARY KEY (ID),
FOREIGN KEY (u_id) REFERENCES utente(ID)
);
I've already searched to solve my problem here but I've found no solution.
Copy your
.sql
file in thedocker-entrypoint-initdb.d
directory..sql file:
Dockerfile:
Reference: https://hub.docker.com/_/mysql/, "Initializing a fresh instance" section:
If your using a dockerfile - then add something like
Or if your using docker-compse
In my case the last one has a directory called SQL with the scripts in it.