3

Does anybody knows how to install mysql-server via dockerfile? I have written a Dockerfile, but the build ends with an error: /bin/sh: 1: /usr/bin/mysqld: not found

USER root

RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server-5.7

# Remove pre-installed database
RUN rm -rf /var/lib/mysql/*

RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/"/etc/mysql/my.cnf

ENV DB_USER example
ENV DB_PASSWORD example
ENV DB_NAME example
ENV VOLUME_HOME "/var/lib/mysql"

EXPOSE 3306 

RUN cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
RUN /usr/bin/mysqld  && sleep 5 && \
     mysql -uroot -e "CREATE USER '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}'" && \
     mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${DB_USER}'@'%' WITH GRANT OPTION" &&\
     mysql -uroot -e "CREATE DATABASE ${DB_NAME}" && \
     mysqladmin -uroot shutdown
4
  • What base image are you using? Commented Nov 16, 2017 at 15:07
  • 1
    FROM ubuntu:16.04 Commented Nov 16, 2017 at 15:10
  • Why not use the official image or use their Dockerfile as a base? Commented Nov 16, 2017 at 15:15
  • I have configured my Jenkins to run our Build Jobs and functional Tests in a docker container. For example, when I click on the "Build Now"-Button - Jenkins will build the Dockerfile which is in Git and run the container so the Buildsteps (Jenkinsfile) can be done in this container. And know I need a mysql-server installed in this too. Commented Nov 16, 2017 at 15:22

1 Answer 1

1

For an ubuntu:16.04 base image, mysqld is found in /usr/sbin, not /usr/bin

If you can add a step RUN which mysqld before your final RUN command that will show you where the mysqld executable is found. It may vary depending on which base image/distro you're using.

You can also use RUN mysqld ... without a full path, if the file is in your $PATH

You may also need to update your RUN sed line as below, adding spaces around the quoted string:

RUN sed -i -e "s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf

Otherwise, you may see the following error:

The command '/bin/sh -c sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/"/etc/mysql/my.cnf' returned a non-zero code: 1
Sign up to request clarification or add additional context in comments.

4 Comments

you are right mysqld is found in usr/sbin. But now i get an non-zero-code: 1. Can you see anything wrong in my "Script"?
@adbo Yes, you also need to edit your RUN sed line, I believe. Will update my answer to note the sed error as well
This line succeeds with no failure - I am getting the non-zero code in: RUN /usr/bin/mysqld && sleep 5 && \ mysql -uroot -e "CREATE USER '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}'" && \ mysql -uroot -e "GRANT ALL PRIVILEGES ON . TO '${DB_USER}'@'%' WITH GRANT OPTION" &&\ mysql -uroot -e "CREATE DATABASE ${DB_NAME}" && \ mysqladmin -uroot shutdown
@adbo This is drifting into mysql errors, rather than docker errors but hopefully someone can jump in with some mysql experience. With a fresh/clean container I can run mysqld --initialize, log in, change the root user password and get everything to work. To script that out you might look here: stackoverflow.com/q/2995054/2892779). Also, you might look at the mysql docker image itself, versus starting this up yourself. There's a convention for setting the user/pass via ARG/ENV variables that might be easier to setup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.