mirror of
https://gitee.com/kennylee/docker.git
synced 2024-11-29 18:38:34 +08:00
优化springboot的wait-for-mysql镜像
This commit is contained in:
parent
56fa85728e
commit
554f501113
@ -6,4 +6,7 @@ RUN apk --no-cache update && \
|
||||
apk --no-cache add mysql-client && \
|
||||
rm -fr /tmp/* /var/cache/apk/*
|
||||
|
||||
ENTRYPOINT "/entrypoint.sh"
|
||||
COPY wait-for-mysql.sh /wait-for-mysql.sh
|
||||
RUN chmod +x /wait-for-mysql.sh
|
||||
|
||||
ENTRYPOINT ["/wait-for-mysql.sh"]
|
45
springboot/image-build/wait-for-mysql/wait-for-mysql.sh
Normal file
45
springboot/image-build/wait-for-mysql/wait-for-mysql.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# wait until MySQL is really available
|
||||
max_counter=45
|
||||
|
||||
port=3306
|
||||
host=localhost
|
||||
username=root
|
||||
password=
|
||||
|
||||
cmd="$@"
|
||||
|
||||
if [[ -n "${MYSQL_PORT}" ]]; then
|
||||
port="${MYSQL_PORT}"
|
||||
fi
|
||||
if [[ -n "${MYSQL_HOST}" ]]; then
|
||||
host="${MYSQL_HOST}"
|
||||
fi
|
||||
if [[ -n "${MYSQL_USER}" ]]; then
|
||||
username="${MYSQL_USER}"
|
||||
fi
|
||||
if [[ -n "${MYSQL_PASSWORD}" ]]; then
|
||||
password="${MYSQL_PASSWORD}"
|
||||
fi
|
||||
|
||||
password_arg=
|
||||
if [[ -n ${password} ]]; then
|
||||
password_arg="-p${password}"
|
||||
fi
|
||||
|
||||
counter=1
|
||||
waiting_dot='.'
|
||||
while ! mysql --protocol TCP -h"${host}" -P"${port}" -u"${username}" ${password_arg} -e "show databases;" > /dev/null 2>&1; do
|
||||
sleep 1
|
||||
ehco "${waiting_dot}"
|
||||
waiting_dot+='.'
|
||||
counter=`expr ${counter} + 1`
|
||||
if [[ ${counter} -gt ${max_counter} ]]; then
|
||||
>&2 echo "We have been waiting for MySQL too long already; failing."
|
||||
exit 1
|
||||
fi;
|
||||
done
|
||||
|
||||
echo "MySQL is up - executing command"
|
||||
exec ${cmd}
|
||||
|
Loading…
Reference in New Issue
Block a user