docker-compose run scripts when container is initialized












0















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.










share|improve this question





























    0















    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.










    share|improve this question



























      0












      0








      0








      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.










      share|improve this question
















      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.







      mysql docker docker-compose mysql-workbench docker-entrypoint






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 18 '18 at 1:47







      tilik09

















      asked Nov 18 '18 at 0:56









      tilik09tilik09

      12




      12
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53356959%2fdocker-compose-run-scripts-when-container-is-initialized%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            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.






            share|improve this answer




























              0














              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.






              share|improve this answer


























                0












                0








                0







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 18 '18 at 2:23









                tilik09tilik09

                12




                12






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53356959%2fdocker-compose-run-scripts-when-container-is-initialized%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()