I want to add a table to my MariaDB database inside a Docker container.
Consider the files tree
$ tree
├── Dockerfile
└── sql
└── test.sql
with the Dockerfile
FROM mariadb:latest
COPY sql/test.sql /docker-entrypoint-initdb.d/
ENV MYSQL_ROOT_PASSWORD test123
ENV MYSQL_DATABASE testDB
ENV MYSQL_USER toto
ENV MYSQL_PASSWORD test123
RUN apt-get update && apt-get -y install vim
EXPOSE 3306
CMD ["mysqld"]
And the sql file
$ cat sql/test.sql
CREATE TABLE IF NOT EXISTS test (
id int NOT NULL AUTO_INCREMENT,
name varchar(32) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO test (name) VALUES
('Toto'),
('Jack'),
('Titi');
I use build --tag=mariadbtest . to build the image and the run it with
docker run --name mariadb -ti -d -p 3307:3306 mariatest
when I log in with
mysql --host=0.0.0.0 --port=3307 mysql -u root -p
I am unable to find the table test. How can I add tables to the database?