🐛fix(): fix bug add docker-compose

Signed-off-by: ehlxr <ehlxr.me@gmail.com>
This commit is contained in:
ehlxr 2018-03-30 18:41:51 +08:00
parent 924b7874c4
commit 4ebec1bde5
4 changed files with 25 additions and 14 deletions

View File

@ -2,7 +2,7 @@ FROM alpine:latest
LABEL maintainer="ehlxr.me@gmail.com"
WORKDIR /app
VOLUME /app
VOLUME /data
RUN apk add --update --no-cache mysql mysql-client \
&& rm -f /var/cache/apk/*

View File

@ -4,12 +4,24 @@ 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
```
# build image (docker-compose)
```
docker-compose build
```
# 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
docker run -it --name mysql -p 3306:3306 -v $(pwd)/db-data:/data -e MYSQL_DATABASE=admin -e MYSQL_USER=ehlxr -e MYSQL_PASSWORD=prY6KaQC -e MYSQL_ROOT_PASSWORD=eDWyvjS2 ehlxr/alpine-mysql
```
It will create a new db, and set mysql root password(default is 111111)
> It will create a new db(default is `admin`) whith user `ehlxr` set password is `prY6KaQC`, and set mysql root password(default is `#Q*2.&tY`)
# Usage (docker-compose)
```
docker-compose up -d
```
> It will create a new db(default is `admin`) whith user `ehlxr` set password is `prY6KaQC`, and set mysql root password(default is `eDWyvjS2`)

View File

@ -1,5 +1,5 @@
[mysqld]
user = root
datadir = /app/mysql
datadir = /data/mysql
port = 3306
log-bin = /app/mysql/mysql-bin
log-bin = /data/mysql/mysql-bin

View File

@ -1,6 +1,10 @@
#!/bin/sh
if [ -d /app/mysql ]; then
if [ ! -d "/run/mysqld" ]; then
mkdir -p /run/mysqld
fi
if [ -d /data/mysql ]; then
echo "[i] MySQL directory already present, skipping creation"
else
echo "[i] MySQL data directory not found, creating initial DBs"
@ -8,7 +12,7 @@ else
mysql_install_db --user=root > /dev/null
if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then
MYSQL_ROOT_PASSWORD=111111
MYSQL_ROOT_PASSWORD=eDWyvjS2
echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD"
fi
@ -16,10 +20,6 @@ else
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
@ -47,5 +47,4 @@ EOF
rm -f $tfile
fi
exec /usr/bin/mysqld --user=root --console
exec /usr/bin/mysqld --user=root --console