如何通过dockerfile安装mysql-server

时间:2017-11-16 14:52:05

标签: mysql docker dockerfile

有谁知道如何通过dockerfile安装mysql-server?我编写了一个Dockerfile,但构建结束时出现错误: / 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

1 个答案:

答案 0 :(得分:1)

对于ubuntu:16.04基本图片,/usr/sbin中找不到/usr/bin,而不是RUN which mysqld

如果您可以在最终的RUN命令之前添加步骤RUN mysqld ...,该命令将显示找到mysqld可执行文件的位置。它可能会有所不同,具体取决于您使用的基本图像/发行版。

如果文件位于$PATH

,您也可以在没有完整路径的情况下使用RUN sed

您可能还需要更新RUN sed -i -e "s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf 行,如下所示:在引用的字符串周围添加空格:

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

否则,您可能会看到以下错误:

    imageView.setImage(ImageSource.uri( imagePath));
    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent)
        {
                float x = motionEvent.getRawX();
                float y = motionEvent.getRawY();
                if(motionEvent.getAction() == 1)
                {
                    PointF pinPoint = new PointF(x , y);
                    if(imageView.isReady())
                    {
                        imageView.setPin(pinPoint);
                    }
                }

            return false;
        }
    });