Search code examples
dockermysql4

docker mysql 4.0.27 start problem after creating dockerfile entrypoint.sh


I have created a docker image, and I have problem to start automatically or even start mysql. The problem is echo "$@" in entrypoint.sh, I expect to run mysqld_safe, but It doesn't. If a change the line echo "$@" to mysqld_safe --user=mysql it starts successfully. I don't know what is the correct form for run automatically as mysql_safe --user=mysql. What should to write in dockerfile CMD[] to run entrypoint.sh correctly.

My code is next:

-----------
Dockerfile:
-----------


## OS part
## -------
FROM debian:buster-slim

# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql

#RUN apt-get update && apt-get install -y --no-install-recommends gnupg dirmngr && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends gnupg dirmngr

# Add packages for testing
RUN apt-get install iproute2 iputils-ping net-tools vim traceroute less -y

## MYSQL part
##-----------
ENV PATH /usr/local/mysql/bin:$PATH
#ENV MYSQLDATA /usr/local/mysql/data

VOLUME /usr/local/mysql/

ADD  mysql-standard-4.0.27-pc-linux-gnu-i686 /usr/local/mysql
ADD  my.cnf /etc/

#RUN chown -R mysql /usr/local/mysql/ && chgrp -R mysql /usr/local/mysql/

COPY entrypoint.sh /usr/local/bin/
#RUN chmod +x /entrypoint.sh
EXPOSE 3306

ENTRYPOINT ["entrypoint.sh"]
CMD ["mysqld_safe"]


---------------
Entrypoint.sh:
---------------


#!/bin/bash
set -e

# global variable
setup_env() {
        MYSQLDATA="/usr/local/mysql/data"
        MYSQLBASE="/usr/local/mysql"
        MYSQL_ROOT_PASSWORD="password"
}

# init database
init__database_dir() {
        echo "Change rights ..."
        ls -la  "$MYSQLDATA"
        chown -R mysql "$MYSQLDATA"
        chgrp -R mysql "$MYSQLDATA"
        echo "Initializing database..."
        cd $MYSQLBASE
        scripts/mysql_install_db --user=mysql
}

temp_server_start() {
        mysqld_safe --user=mysql  &
}

temp_server_stop() {
        mysqladmin shutdown -uroot
        sleep 30
}

setup_db() {
        sleep 20
        echo "start password setting"
        mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION"
        echo "password ready"
}

# start mysql if it is exist.
main() {
        setup_env
        if [ -z "$(ls -A "$MYSQLDATA/mysql/")" ]; then
                init__database_dir
                temp_server_start
                setup_db
                temp_server_stop
        fi
        echo "start mysqld_safe"
        echo "$@"
}

main


Solution

  • I think you forgot to pass the parameters in your entrypoint.sh. The last line should be

    main "$@"