How to install mysql-server in a Dockerfile?












0














I have a complex Dockerfile which install much more than just mysql-server so I cannot start from an existing mysql container.



When removing all the extra-stuff I get this Dockerfile



FROM ubuntu:latest

ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_ROOT_USER=root
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y mysql-server

RUN usermod -d /var/lib/mysql/ mysql
RUN service mysql start


Unfortunately, mysql does not want to start:



 ---> 57a66bd64c2c
Step 8/9 : RUN usermod -d /var/lib/mysql/ mysql
---> Running in 596df248c2e4
---> ee78442bcc56
Step 9/9 : RUN service mysql start
---> Running in 0d9e5803cf33
* Starting MySQL database server mysqld
...fail!
The command '/bin/sh -c service mysql start' returned a non-zero code: 1


What is my mistake?










share|improve this question



























    0














    I have a complex Dockerfile which install much more than just mysql-server so I cannot start from an existing mysql container.



    When removing all the extra-stuff I get this Dockerfile



    FROM ubuntu:latest

    ENV MYSQL_ROOT_PASSWORD=root
    ENV MYSQL_ROOT_USER=root
    ENV DEBIAN_FRONTEND=noninteractive

    RUN apt-get update
    RUN apt-get install -y apt-utils
    RUN apt-get install -y mysql-server

    RUN usermod -d /var/lib/mysql/ mysql
    RUN service mysql start


    Unfortunately, mysql does not want to start:



     ---> 57a66bd64c2c
    Step 8/9 : RUN usermod -d /var/lib/mysql/ mysql
    ---> Running in 596df248c2e4
    ---> ee78442bcc56
    Step 9/9 : RUN service mysql start
    ---> Running in 0d9e5803cf33
    * Starting MySQL database server mysqld
    ...fail!
    The command '/bin/sh -c service mysql start' returned a non-zero code: 1


    What is my mistake?










    share|improve this question

























      0












      0








      0







      I have a complex Dockerfile which install much more than just mysql-server so I cannot start from an existing mysql container.



      When removing all the extra-stuff I get this Dockerfile



      FROM ubuntu:latest

      ENV MYSQL_ROOT_PASSWORD=root
      ENV MYSQL_ROOT_USER=root
      ENV DEBIAN_FRONTEND=noninteractive

      RUN apt-get update
      RUN apt-get install -y apt-utils
      RUN apt-get install -y mysql-server

      RUN usermod -d /var/lib/mysql/ mysql
      RUN service mysql start


      Unfortunately, mysql does not want to start:



       ---> 57a66bd64c2c
      Step 8/9 : RUN usermod -d /var/lib/mysql/ mysql
      ---> Running in 596df248c2e4
      ---> ee78442bcc56
      Step 9/9 : RUN service mysql start
      ---> Running in 0d9e5803cf33
      * Starting MySQL database server mysqld
      ...fail!
      The command '/bin/sh -c service mysql start' returned a non-zero code: 1


      What is my mistake?










      share|improve this question













      I have a complex Dockerfile which install much more than just mysql-server so I cannot start from an existing mysql container.



      When removing all the extra-stuff I get this Dockerfile



      FROM ubuntu:latest

      ENV MYSQL_ROOT_PASSWORD=root
      ENV MYSQL_ROOT_USER=root
      ENV DEBIAN_FRONTEND=noninteractive

      RUN apt-get update
      RUN apt-get install -y apt-utils
      RUN apt-get install -y mysql-server

      RUN usermod -d /var/lib/mysql/ mysql
      RUN service mysql start


      Unfortunately, mysql does not want to start:



       ---> 57a66bd64c2c
      Step 8/9 : RUN usermod -d /var/lib/mysql/ mysql
      ---> Running in 596df248c2e4
      ---> ee78442bcc56
      Step 9/9 : RUN service mysql start
      ---> Running in 0d9e5803cf33
      * Starting MySQL database server mysqld
      ...fail!
      The command '/bin/sh -c service mysql start' returned a non-zero code: 1


      What is my mistake?







      mysql docker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 '18 at 13:34









      nowoxnowox

      6,07593298




      6,07593298
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.



          FROM oraclelinux:7-slim
          ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm

          # Install server
          RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql
          && yum install -y $PACKAGE_URL
          && yum install -y libpwquality
          && rm -rf /var/cache/yum/*
          RUN mkdir /docker-entrypoint-initdb.d

          VOLUME /var/lib/mysql

          COPY docker-entrypoint.sh /entrypoint.sh
          ENTRYPOINT ["/entrypoint.sh"]

          EXPOSE 3306 33060
          CMD ["mysqld"]


          You need to include a proper source with correct version to pull the image from.
          and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
          Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.






          share|improve this answer





















          • Yeah but I do not want to expose any port and do anything from an official docker file. I would like to install mysql on my own container.
            – nowox
            Nov 18 '18 at 13:52










          • The example you gave is not using Ubuntu 18.04 which is the distribution I need to use...
            – nowox
            Nov 18 '18 at 13:53






          • 1




            if you don't expose any ports how do you plan to interface with the database? and your system OS doesn't really matter in docker.
            – AACaN
            Nov 18 '18 at 14:00











          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%2f53361442%2fhow-to-install-mysql-server-in-a-dockerfile%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














          Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.



          FROM oraclelinux:7-slim
          ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm

          # Install server
          RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql
          && yum install -y $PACKAGE_URL
          && yum install -y libpwquality
          && rm -rf /var/cache/yum/*
          RUN mkdir /docker-entrypoint-initdb.d

          VOLUME /var/lib/mysql

          COPY docker-entrypoint.sh /entrypoint.sh
          ENTRYPOINT ["/entrypoint.sh"]

          EXPOSE 3306 33060
          CMD ["mysqld"]


          You need to include a proper source with correct version to pull the image from.
          and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
          Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.






          share|improve this answer





















          • Yeah but I do not want to expose any port and do anything from an official docker file. I would like to install mysql on my own container.
            – nowox
            Nov 18 '18 at 13:52










          • The example you gave is not using Ubuntu 18.04 which is the distribution I need to use...
            – nowox
            Nov 18 '18 at 13:53






          • 1




            if you don't expose any ports how do you plan to interface with the database? and your system OS doesn't really matter in docker.
            – AACaN
            Nov 18 '18 at 14:00
















          0














          Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.



          FROM oraclelinux:7-slim
          ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm

          # Install server
          RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql
          && yum install -y $PACKAGE_URL
          && yum install -y libpwquality
          && rm -rf /var/cache/yum/*
          RUN mkdir /docker-entrypoint-initdb.d

          VOLUME /var/lib/mysql

          COPY docker-entrypoint.sh /entrypoint.sh
          ENTRYPOINT ["/entrypoint.sh"]

          EXPOSE 3306 33060
          CMD ["mysqld"]


          You need to include a proper source with correct version to pull the image from.
          and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
          Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.






          share|improve this answer





















          • Yeah but I do not want to expose any port and do anything from an official docker file. I would like to install mysql on my own container.
            – nowox
            Nov 18 '18 at 13:52










          • The example you gave is not using Ubuntu 18.04 which is the distribution I need to use...
            – nowox
            Nov 18 '18 at 13:53






          • 1




            if you don't expose any ports how do you plan to interface with the database? and your system OS doesn't really matter in docker.
            – AACaN
            Nov 18 '18 at 14:00














          0












          0








          0






          Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.



          FROM oraclelinux:7-slim
          ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm

          # Install server
          RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql
          && yum install -y $PACKAGE_URL
          && yum install -y libpwquality
          && rm -rf /var/cache/yum/*
          RUN mkdir /docker-entrypoint-initdb.d

          VOLUME /var/lib/mysql

          COPY docker-entrypoint.sh /entrypoint.sh
          ENTRYPOINT ["/entrypoint.sh"]

          EXPOSE 3306 33060
          CMD ["mysqld"]


          You need to include a proper source with correct version to pull the image from.
          and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
          Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.






          share|improve this answer












          Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.



          FROM oraclelinux:7-slim
          ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm

          # Install server
          RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql
          && yum install -y $PACKAGE_URL
          && yum install -y libpwquality
          && rm -rf /var/cache/yum/*
          RUN mkdir /docker-entrypoint-initdb.d

          VOLUME /var/lib/mysql

          COPY docker-entrypoint.sh /entrypoint.sh
          ENTRYPOINT ["/entrypoint.sh"]

          EXPOSE 3306 33060
          CMD ["mysqld"]


          You need to include a proper source with correct version to pull the image from.
          and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
          Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 '18 at 13:51









          AACaNAACaN

          316




          316












          • Yeah but I do not want to expose any port and do anything from an official docker file. I would like to install mysql on my own container.
            – nowox
            Nov 18 '18 at 13:52










          • The example you gave is not using Ubuntu 18.04 which is the distribution I need to use...
            – nowox
            Nov 18 '18 at 13:53






          • 1




            if you don't expose any ports how do you plan to interface with the database? and your system OS doesn't really matter in docker.
            – AACaN
            Nov 18 '18 at 14:00


















          • Yeah but I do not want to expose any port and do anything from an official docker file. I would like to install mysql on my own container.
            – nowox
            Nov 18 '18 at 13:52










          • The example you gave is not using Ubuntu 18.04 which is the distribution I need to use...
            – nowox
            Nov 18 '18 at 13:53






          • 1




            if you don't expose any ports how do you plan to interface with the database? and your system OS doesn't really matter in docker.
            – AACaN
            Nov 18 '18 at 14:00
















          Yeah but I do not want to expose any port and do anything from an official docker file. I would like to install mysql on my own container.
          – nowox
          Nov 18 '18 at 13:52




          Yeah but I do not want to expose any port and do anything from an official docker file. I would like to install mysql on my own container.
          – nowox
          Nov 18 '18 at 13:52












          The example you gave is not using Ubuntu 18.04 which is the distribution I need to use...
          – nowox
          Nov 18 '18 at 13:53




          The example you gave is not using Ubuntu 18.04 which is the distribution I need to use...
          – nowox
          Nov 18 '18 at 13:53




          1




          1




          if you don't expose any ports how do you plan to interface with the database? and your system OS doesn't really matter in docker.
          – AACaN
          Nov 18 '18 at 14:00




          if you don't expose any ports how do you plan to interface with the database? and your system OS doesn't really matter in docker.
          – AACaN
          Nov 18 '18 at 14:00


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53361442%2fhow-to-install-mysql-server-in-a-dockerfile%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







          Popular posts from this blog

          How to send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?