skip to Main Content

Docker logs:

1

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search