gpt4 book ai didi

docker - 创建dockerfile entrypoint.sh后docker mysql 4.0.27启动问题

转载 作者:行者123 更新时间:2023-12-02 21:32:21 28 4
gpt4 key购买 nike

我已经创建了一个docker镜像,但是我无法自动启动甚至启动mysql。
问题是"$@"中的echo entrypoint.sh,我希望运行mysqld_safe,但事实并非如此。如果将行echo "$@"更改为mysqld_safe --user=mysql,它将成功启动。我不知道什么是自 Action 为mysql_safe --user=mysql运行的正确形式。在dockerfile CMD[]中应该写什么才能正确运行entrypoint.sh
接下来是我的代码:

-----------
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

最佳答案

我认为您忘记了在entrypoint.sh中传递参数。最后一行应该是

main "$@"

关于docker - 创建dockerfile entrypoint.sh后docker mysql 4.0.27启动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64156551/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com