✨ feat(): add alpine mysql dockerfile
Signed-off-by: ehlxr <ehlxr.me@gmail.com>
This commit is contained in:
parent
26eacaaab8
commit
924b7874c4
14
alpine-mysql/Dockerfile
Normal file
14
alpine-mysql/Dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="ehlxr.me@gmail.com"
|
||||
|
||||
WORKDIR /app
|
||||
VOLUME /app
|
||||
|
||||
RUN apk add --update --no-cache mysql mysql-client \
|
||||
&& rm -f /var/cache/apk/*
|
||||
|
||||
COPY my.cnf /etc/mysql/my.cnf
|
||||
COPY startup.sh /startup.sh
|
||||
|
||||
EXPOSE 3306
|
||||
CMD ["/startup.sh"]
|
15
alpine-mysql/README.md
Normal file
15
alpine-mysql/README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# alpine-mysql
|
||||
a docker image base on alpine with mysql
|
||||
|
||||
# build image
|
||||
```
|
||||
docker build -t ehlxr/alpine-mysql .
|
||||
docker run -it --rm -v $(pwd):/app -p 3306:3306 ehlxr/alpine-mysql
|
||||
```
|
||||
|
||||
# Usage
|
||||
```
|
||||
docker run -it --name mysql -p 3306:3306 -v $(pwd):/app -e MYSQL_DATABASE=admin -e MYSQL_USER=tony -e MYSQL_PASSWORD=dpa\*12d -e MYSQL_ROOT_PASSWORD=111111 ehlxr/alpine-mysql
|
||||
```
|
||||
|
||||
It will create a new db, and set mysql root password(default is 111111)
|
5
alpine-mysql/my.cnf
Normal file
5
alpine-mysql/my.cnf
Normal file
@ -0,0 +1,5 @@
|
||||
[mysqld]
|
||||
user = root
|
||||
datadir = /app/mysql
|
||||
port = 3306
|
||||
log-bin = /app/mysql/mysql-bin
|
51
alpine-mysql/startup.sh
Executable file
51
alpine-mysql/startup.sh
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -d /app/mysql ]; then
|
||||
echo "[i] MySQL directory already present, skipping creation"
|
||||
else
|
||||
echo "[i] MySQL data directory not found, creating initial DBs"
|
||||
|
||||
mysql_install_db --user=root > /dev/null
|
||||
|
||||
if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then
|
||||
MYSQL_ROOT_PASSWORD=111111
|
||||
echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD"
|
||||
fi
|
||||
|
||||
MYSQL_DATABASE=${MYSQL_DATABASE:-""}
|
||||
MYSQL_USER=${MYSQL_USER:-""}
|
||||
MYSQL_PASSWORD=${MYSQL_PASSWORD:-""}
|
||||
|
||||
if [ ! -d "/run/mysqld" ]; then
|
||||
mkdir -p /run/mysqld
|
||||
fi
|
||||
|
||||
tfile=`mktemp`
|
||||
if [ ! -f "$tfile" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
cat << EOF > $tfile
|
||||
USE mysql;
|
||||
FLUSH PRIVILEGES;
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "$MYSQL_ROOT_PASSWORD" WITH GRANT OPTION;
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
|
||||
UPDATE user SET password=PASSWORD("") WHERE user='root' AND host='localhost';
|
||||
EOF
|
||||
|
||||
if [ "$MYSQL_DATABASE" != "" ]; then
|
||||
echo "[i] Creating database: $MYSQL_DATABASE"
|
||||
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile
|
||||
|
||||
if [ "$MYSQL_USER" != "" ]; then
|
||||
echo "[i] Creating user: $MYSQL_USER with password $MYSQL_PASSWORD"
|
||||
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
|
||||
fi
|
||||
fi
|
||||
|
||||
/usr/bin/mysqld --user=root --bootstrap --verbose=0 < $tfile
|
||||
rm -f $tfile
|
||||
fi
|
||||
|
||||
|
||||
exec /usr/bin/mysqld --user=root --console
|
Loading…
Reference in New Issue
Block a user