I am new to docker. I am on a windows 7 machine and using docker toolbox. I am trying to write a docker-compose.yml for MySQL which creates a database and runs 2 scripts (create table and insert)
version: '3'
services:
mysql-image:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: myDatabase
MYSQL_USER: test
MYSQL_PASSWORD: pwtest
ports:
- "3306:3306"
volumes:
- ./sqlscripts/:/docker-entrypoint-initdb.d/
volumes:
sqlscripts:
I can connect to the database, but the problem I have is running the scripts. mostly I run into the following error:
mysql-image_1 | mysql: [Warning] Using a password on the command line interface can be insecure.
mysql-image_1 | ERROR: Can't initialize batch_readline - may be the input source is a directory or a block device. docker_mysql-image_1 exited with code 1
I searched for a while, trying to get it work but at this point I do not know what I am doing wrong. This is one of my .sql scripts which I am trying to run it when the docker container starts. createTablePerson.sql
CREATE TABLE `myDatabase`.`Person` (
`idPerson` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`age` INT NOT NULL,
PRIMARY KEY (`idPerson`));
Thanks.
I investigated further and it seems is because I am on Windows 7 and I have to use docker-toolbox which runs in a VirtualBox VM. It seems that the location I had my scripts, is not shared between windows host and docker-toolbox. I noticed the files were copied in the container but they where considered as empty directories. I moved my scripts to user location and it seems the scripts are copied to the container and run perfectly. Now I am searching for a way to try make other paths visible. I prefer to have my scripts under my java project.