Skip to content

Instantly share code, notes, and snippets.

@cesurapp
Created February 3, 2019 17:34
Show Gist options
  • Save cesurapp/d7836eb2306bc7be0f16f0726952b3e9 to your computer and use it in GitHub Desktop.
Save cesurapp/d7836eb2306bc7be0f16f0726952b3e9 to your computer and use it in GitHub Desktop.
MariaDB for Docker Alpine
FROM alpine:latest
# -----------------------------------------------------------------------------
# Install MariaDB
# -----------------------------------------------------------------------------
RUN apk update
RUN apk add pwgen
RUN apk add mariadb mariadb-client
RUN rm -f /var/cache/apk/*
# -----------------------------------------------------------------------------
# Entrypoint & Config
# -----------------------------------------------------------------------------
ADD my.cnf /etc/mysql/
ADD entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
VOLUME ["/var/lib/mysql"]
EXPOSE 3306
CMD ["entrypoint.sh"]
#!/bin/sh
if [ -d "/run/mysqld" ]
then
chown -R mysql:mysql /run/mysqld
else
mkdir -p /run/mysqld
chown -R mysql:mysql /run/mysqld
fi
if [ -d /var/lib/mysql/mysql ]
then
chown -R mysql:mysql /var/lib/mysql
else
chown -R mysql:mysql /var/lib/mysql
mysql_install_db --user=mysql > /dev/null
if [ "$MYSQL_ROOT_PASSWORD" = "" ]
then
MYSQL_ROOT_PASSWORD=`pwgen 16 1`
echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD"
fi
MYSQL_DATABASE=${MYSQL_DATABASE:-""}
MYSQL_USER=${MYSQL_USER:-""}
MYSQL_PASSWORD=${MYSQL_PASSWORD:-""}
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' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION;
UPDATE user SET password=PASSWORD("") WHERE user='root' AND host='localhost';
DROP DATABASE test;
EOF
if [ "$MYSQL_DATABASE" != "" ]
then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile
if [ "$MYSQL_USER" != "" ]
then
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
fi
fi
/usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve < $tfile
rm -f $tfile
fi
exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve $@
[mysqld]
innodb_buffer_pool_size=100M
innodb_log_file_size=25M
key_buffer = 8M
thread_stack = 128K
query_cache_size = 8M
query_cache_limit = 512K
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment