Docker logs:
I use the powershell script to run the container:
docker rm ctnr-mariadb --force
docker pull mariadb:latest
docker run --name ctnr-mariadb -e MYSQL_ROOT_PASSWORD=example -e MARIADB_USER=user -e MARIADB_PASSWORD=password -e MARIADB_DATABASE=repo -p 1234:3306 -detach mariadb -v sql/init.sql:/docker-entrypoint-initdb.d/init.sql
inside init.sql there is a following script
`CREATE TABLE `Contacts` (
`Id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;`
My aim is just to initialize a maria db container with some sql scripts bootsrapping database and tables. i have no idea what to do based on the log messages.
CodePudding user response:
your SQL-File is not a file to configure the mariadb instance. You can split up your commands like the following code snippet:
docker rm ctnr-mariadb --force
docker pull mariadb:latest
docker run --name ctnr-mariadb -e MYSQL_ROOT_PASSWORD=example -e MARIADB_USER=user -e MARIADB_PASSWORD=password -e MARIADB_DATABASE=repo -p 1234:3306 -detach mariadb
docker exec -i ctnr-mariadb sh -c 'exec mariadb -uroot -pexample repo' < ./sql/init.sql
Attention: I have hard coded the environment variables in the last command.
CodePudding user response:
As per docker run
documentation all Docker arguments must be placed before the image name. Everything after the image name is a command to be run inside the image (equivalent to CMD in Dockerfile).
With that in mind your docker run
command should be:
docker run --name ctnr-mariadb -e MYSQL_ROOT_PASSWORD=example -e MARIADB_USER=user -e MARIADB_PASSWORD=password -e MARIADB_DATABASE=repo -p 1234:3306 --detach -v sql/init.sql:/docker-entrypoint-initdb.d/init.sql mariadb