From e185c732dcd7a38eb6d835b4acc8a837dd3c6003 Mon Sep 17 00:00:00 2001 From: a-sansara Date: Mon, 1 Aug 2016 04:22:06 +0200 Subject: [PATCH] mysql : add various scripts all : fix terminal ENV context and add doc nav --- DOCKER.md | 133 ++++++++++++++++++ README.md | 15 +- pluie/alpine-apache/README.md | 11 ++ pluie/alpine-apache/files.tar | Bin 10240 -> 10240 bytes pluie/alpine-mysql/README.md | 121 ++++++++++++---- pluie/alpine-mysql/createdb.sh | 32 ----- pluie/alpine-mysql/dbcommon.sh | 35 +++++ pluie/alpine-mysql/dbcreate.sh | 42 ++++++ pluie/alpine-mysql/dbdump.sh | 23 +++ pluie/alpine-mysql/dbload.sh | 28 ++++ pluie/alpine-mysql/files.tar | Bin 10240 -> 20480 bytes .../alpine-mysql/install.d/40-scripts-fix.sh | 3 + pluie/alpine/README.md | 12 +- pluie/alpine/files.tar | Bin 20480 -> 20480 bytes pluie/alpine/util.sh | 8 +- 15 files changed, 394 insertions(+), 69 deletions(-) create mode 100644 DOCKER.md delete mode 100644 pluie/alpine-mysql/createdb.sh create mode 100644 pluie/alpine-mysql/dbcommon.sh create mode 100755 pluie/alpine-mysql/dbcreate.sh create mode 100755 pluie/alpine-mysql/dbdump.sh create mode 100755 pluie/alpine-mysql/dbload.sh create mode 100644 pluie/alpine-mysql/install.d/40-scripts-fix.sh diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..3fc62ce --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,133 @@ +## Docker + +- [index][1] +- [image pluie/alpine][2] +- [image pluie/alpine-mysql][3] +- [image pluie/alpine-apache][4] + +### Networking + +#### create network +``` +docker network create \ +--subnet=172.22.0.0/16 \ +--gateway=172.22.0.1 \ +-o "com.docker.network.bridge.name"="home0" \ +home0 +``` + +#### inspect ip +``` +docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container +``` + +#### /etc/hosts +``` +# > DOCKER - bridge home0 +172.22.0.2 db.docker +172.22.0.3 gogs.docker +172.22.0.4 pma.docker +172.22.0.5 bo-payment.docker +172.22.0.6 wordpress.docker +# < + +``` + +### Util + +#### remove all container +``` +docker rm $(docker ps -a -q) +``` +rm -v to also remove volume +rm -f to force stop running container before removing + + +#### remove none images +``` +docker rmi $(docker images | grep "^" | awk "{print $3}") +``` + +#### remove all volumes +``` +docker volume rm $(docker volume ls -qf dangling=true) +``` + +#### logs container +``` +docker logs -f container +``` + +#### stats container +``` +docker stats container +``` + +### Pluie container + +#### map + +[db.docker] (http://db.docker) +[pma.docker] (http://pma.docker) +[gogs.docker] (http://gogs.docker) +[bo-payment.docker] (http://bo-payment.docker) +[wordpress.docker] (http://wordpress.docker) + +#### Mysql +``` +cd /home/dev/docker + +docker run --name mysql --restart=always \ +--net home0 -h db.docker --ip 172.22.0.2 \ +-v $(pwd)/db/mysql:/var/lib/mysql \ +-v $(pwd)/db/dump:/dump \ +-e MYSQL_DATABASE=bo-payment \ +-e MYSQL_USER=dev \ +-e MYSQL_PASSWORD=mysql \ +-d pluie/alpine-mysql +``` + +#### Gogs +``` +cd /home/dev/docker + +docker run --name gogs --restart=always \ +--net home0 -h gogs.docker --ip 172.22.0.3 --link mysql:db \ +-v $(pwd)/gogs:/data \ +gogs/gogs +``` + +#### Phpmyadmin +``` +docker run --name pma --restart=always \ +--net home0 -h pma.docker --ip 172.22.0.4 --link mysql:db \ +-d phpmyadmin/phpmyadmin +``` + +#### Apache +``` +cd /home/dev/docker + +docker run --name apache --restart=always \ +--net home0 -h bo-payment.docker --ip 172.22.0.5 --link mysql:db \ +-v $(pwd)/repo/bo-payment:/app \ +-e HTTP_SERVER_NAME=bo-payment.docker \ +-d pluie/alpine-apache +``` + +#### Wordpress +``` +cd /home/dev/docker + +docker run --name wordpress --restart=always \ +--net home0 -h wordpress.docker --ip 172.22.0.6 --link mysql:db \ +-v $(pwd)/blog:/app \ +-e HTTP_SERVER_NAME=wordpress.docker \ +-d pluie/alpine-apache +``` + + [1]: https://github.com/pluie-org/docker-images + [2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine + [3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql + [4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache + [5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md diff --git a/README.md b/README.md index 4dc7f7e..6ac9130 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ # docker-images -based images for Docker +various based images for Docker ## Available Images -- __pluie/alpine__ ( < 10 MB) Alpine/3.4 -- __pluie/alpine-apache__ ( ~ 50 MB) Apache/2.4.23 Php/5.6.24 -- __pluie/alpine-mysql__ ( ~ 172 MB) Mysql/5.5.47 [MariaDB] +- [pluie/alpine][2] ( < 10 MB ) Alpine/3.4 +- [pluie/alpine-apache][3] ( ~ 50 MB ) Apache/2.4.23 Php/5.6.24 +- [pluie/alpine-mysql][4] ( ~172 MB ) Mysql/5.5.47 ( MariaDB ) +- [docker tips][5] ## Base Image Structure @@ -67,3 +68,9 @@ __build__ script archive project files in __files.tar__ then execute the __Docke no need to worry about pwd, docker repository and image name depends on directory structure. you can keep same __build__ script in any project + + [1]: https://github.com/pluie-org/docker-images + [2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine + [3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql + [4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache + [5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md diff --git a/pluie/alpine-apache/README.md b/pluie/alpine-apache/README.md index 36d481b..958ce70 100644 --- a/pluie/alpine-apache/README.md +++ b/pluie/alpine-apache/README.md @@ -1,5 +1,10 @@ # pluie/alpine-apache +- [index][1] +- [image pluie/alpine][2] +- [image pluie/alpine-mysql][3] +- [docker tips][5] + Extend pluie/alpine with __apache 2.4.23__ and __php 5.6.24__ - error log are attached to stdout @@ -54,3 +59,9 @@ for more commands : ``` $ docker exec -it apache "httpd -h" ``` + + [1]: https://github.com/pluie-org/docker-images + [2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine + [3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql + [4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache + [5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md diff --git a/pluie/alpine-apache/files.tar b/pluie/alpine-apache/files.tar index 3032c2974f73128367a15d3c952a6b71ecb8e6b8..cc7b25324587ff67a2b13a75557e0f2b44d8afec 100644 GIT binary patch delta 221 zcmZn&Xb70lBWP-3Xk=z$%3uJbOpO>63?@4=rfg

|z!&H83(XFflL&${8CQ88RrC zLgZL^87K2`)gsHA8kqp)p?bOhvrJ+`HrdqJ7$M94pJ|dnH?n49BNGF-;ewoulexqi gk>$+{j7;E$ivtZ8LeXw&WNZ$X7XHt)c!LxV0Ac4cApigX delta 221 zcmZn&Xb70lBWPxBYGi6^$Y5Y-WM*o{pkOfBkuha6BV!k{kO@N0*x1CBLBSLv$I8n% znUALqNvo-`F;E(+mG?i>B(`p3-KIdJ;nM8?StbdfNE;iOnZOMf /dump/last.mybase.dump.sql ``` -etc. +etc. -### User usage - -locally (on host) you can run (with appropriate user : pass) : -``` -mysql -h ipmysqlcontainer -udev -pmysql -``` -or if you want use the mysql client of the container : -``` -docker exec -it mysql "mysql -h ipmysqlcontainer -udev -pmysql" -``` - ## Link Container -to link this container to another, use the default docker behavior : +to link this container to another, use the default docker behavior +(as the example provide with phpmyadmin) : ``` docker run --name mycontainer --link mysql:db ... ``` + + + [1]: https://github.com/pluie-org/docker-images + [2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine + [3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql + [4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache + [5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md diff --git a/pluie/alpine-mysql/createdb.sh b/pluie/alpine-mysql/createdb.sh deleted file mode 100644 index 1656e6f..0000000 --- a/pluie/alpine-mysql/createdb.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# pluie/docker-images - a-Sansara (https://github.com/a-sansara) - -dbname=${1:-''} -dbuser=${2:-''} - -echo "dbname : $dbname" -echo "dbuser : $dbuser" - -tfile=`mktemp` -if [ ! -f "$tfile" ]; then - return 1 -fi - -if [ ! -z "$dbname" ]; then - cat < $tfile -CREATE DATABASE IF NOT EXISTS \`$dbname\` CHARACTER SET utf8 COLLATE utf8_general_ci; -EOF - - if [ ! -z "$dbuser" ]; then - cat <> $tfile -GRANT ALL ON \`$dbname\`.* to '$dbuser'@'localhost'; -GRANT ALL ON \`$dbname\`.* to '$dbuser'@'%'; -EOF - fi - - echo "FLUSH PRIVILEGES;" >> $tfile - cat $tfile; - mysql -uroot < $tfile - rm -f $tfile -fi - diff --git a/pluie/alpine-mysql/dbcommon.sh b/pluie/alpine-mysql/dbcommon.sh new file mode 100644 index 0000000..59a50b9 --- /dev/null +++ b/pluie/alpine-mysql/dbcommon.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# pluie/docker-images - a-Sansara (https://github.com/a-sansara) + +Ctitle="\033[1;48;5;30;1;38;5;15m" + Ctext="\033[1;38;5;30m" + Copt="\033[1;38;5;72m" + Cspe="\033[1;38;5;30m" + Cerr="\033[1;38;5;196m" + Cusa="\033[1;38;5;214m" + Coff="\033[m" + +function echoTitle(){ + echo -e "\n ${Ctitle} $shname ${Coff}" +} + +function mktfile(){ + tfile="$(mktemp)" + if [ ! -f "$tfile" ]; then + echoErr "can't make temp file" 1 + exit 1 + fi +} + +function errEmptyDb(){ + echoErr "database can't be empty" +} + +function echoErr(){ + echo -e "\n${Cerr} error : $1${Coff}" + if [ -z "$2" ]; then + usage + fi + echo + exit 1 +} diff --git a/pluie/alpine-mysql/dbcreate.sh b/pluie/alpine-mysql/dbcreate.sh new file mode 100755 index 0000000..7dca600 --- /dev/null +++ b/pluie/alpine-mysql/dbcreate.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# pluie/docker-images - a-Sansara (https://github.com/a-sansara) + +. /scripts/dbcommon.sh + +dbname=${1:-''} +dbuser=${2:-''} +shname=$(basename $0) + +echoTitle + +function usage(){ + echo -e "\n ${Cusa}usage :${Coff}\n ${Ctext}$shname \t${Copt}DBNAME ${Cspe}[${Copt}USER${Cspe}]${Coff}" +} + +mktfile + +if [ ! -z "$dbname" ]; then + cat < "$tfile" +CREATE DATABASE IF NOT EXISTS \`$dbname\` CHARACTER SET utf8 COLLATE utf8_general_ci; +EOF + + if [ ! -z "$dbuser" ]; then + cat <> "$tfile" +GRANT ALL ON \`$dbname\`.* to '$dbuser'@'localhost'; +GRANT ALL ON \`$dbname\`.* to '$dbuser'@'%'; +EOF + fi + + echo "FLUSH PRIVILEGES;" >> "$tfile" + echo + cat "$tfile" | sed "s/^/ /"; + echo + mysql -uroot < "$tfile" + if [ $? -eq 0 ]; then + echo -e "\n done" + fi + echo + rm -f "$tfile" +else + errEmptyDb +fi diff --git a/pluie/alpine-mysql/dbdump.sh b/pluie/alpine-mysql/dbdump.sh new file mode 100755 index 0000000..201f061 --- /dev/null +++ b/pluie/alpine-mysql/dbdump.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# pluie/docker-images - a-Sansara (https://github.com/a-sansara) + +. /scripts/dbcommon.sh + +dbname=${1:-''} +shname=$(basename $0) + +echoTitle + +function usage(){ + echo -e "\n ${Cusa}usage :${Coff}\n ${Ctext}$shname \t${Copt}DBNAME USER${Coff}" +} + +if [ ! -z "$1" ]; then + mysqldump -uroot "$dbname" > "/dump/"$(date +"%y%m%d-%H%I")".$dbname.sql" + if [ $? -eq 0 ]; then + echo -e "\n done" + fi + echo +else + errEmptyDb +fi diff --git a/pluie/alpine-mysql/dbload.sh b/pluie/alpine-mysql/dbload.sh new file mode 100755 index 0000000..046e16e --- /dev/null +++ b/pluie/alpine-mysql/dbload.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# pluie/docker-images - a-Sansara (https://github.com/a-sansara) + +. /scripts/dbcommon.sh + + dbname=${1:-''} +filename=${2} + shname=$(basename $0) + +echoTitle + +function usage(){ + echo -e "\n ${Cusa}usage :${Coff}\n ${Ctext}$shname \t${Copt}DBNAME FILENAME${Coff}" +} + +if [ ! -f "$filename" ]; then + echoErr "unknow file '$filename'" +fi +if [ ! -z "$1" ]; then + mysql -uroot "$dbname" < "$filename" + if [ $? -eq 0 ]; then + echo -e "\n done" + fi + echo +else + errEmptyDb +fi + diff --git a/pluie/alpine-mysql/files.tar b/pluie/alpine-mysql/files.tar index 70d6ea6e1c96a5bf11e710086ec2ca8e68e5100c..41e357f238883fa3f5c502b79e4d07147e563242 100644 GIT binary patch literal 20480 zcmeHNZByGw66UjhMMrC5*gIJ-ej$g~yXRmNTt#rsb}qLCIgqU}sIVoiBnQ}>|NC{% zNU{V3lf))PtxOfxxMx~3Ju^@DJU!NM#@r@JrvRYUyth>4s6+ z&<&IrM!9C}Y-oD9s#iBaTUUqDdS^js`T!fI5|~b4`es^~dR`_^Rees6KfO?gwxbTs z;6nNdyvfXFs^yL@nXlMW^PB~sfT{F_X<+Lj4834iRnP74Vm2({+EEk3Y)jH!XonNl zkWaL7`B<-4Ue&AhvR2pYWqQ)9Q(1z&kX?sK6)q@iB!E5FyCv8$gdp%1N;55(?`Ku% z|EP&3v%t(s480P)Wju}~SeC{!XB67518j8R4ygNE+n=#Bz<&URfqddX;jivC<|PBt0Hj?8eNpk+4x{4O&U6KB)1G?aO>3AQ5m#!Np@~z@KxiK_ zK-J+*b|_>JtetKgnFB|T%IARpTpxC!peMFShNt|AgEQ_94Cm#X@!n&1{y)XqS}p#UKn+H|?S+Ag3o8yR zB*_{QWHt()^t2t=CZuZ;I*@vU<0NVfQ^ap)7Ig2!%oWb5fv)9}k zw0qER4`3FKU%_7Y@Q_+l;q;t2%r_^eBfBo)OC*k-**=kZzu2c#r{46MM+0ac9zyph z-G|c85V}yrK9Q#4KZ_H0WKJ&JAS~9UM>pEU%G5!c14R1-?m^x^eBVEScfHQPJBRHz z?S5T`UsK(p1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KsNqXTKXnluH2!k`qf5 zAY5xOKew{DFh@bRv?xEnM8O6s1(qqwRnSd?38ZCmacxdC>SmlI(k+DKH6t@qbGX+; zyO@#XjEzl985B$*-j?iQM3yr#H2}&%gG9QE8(GfS$P5@T)tq=F&iwH!?7To2~huX>oxO8vtBJZ?pga diff --git a/pluie/alpine-mysql/install.d/40-scripts-fix.sh b/pluie/alpine-mysql/install.d/40-scripts-fix.sh new file mode 100644 index 0000000..a192567 --- /dev/null +++ b/pluie/alpine-mysql/install.d/40-scripts-fix.sh @@ -0,0 +1,3 @@ +mv /scripts/dbdump.sh /dbdump +mv /scripts/dbcreate.sh /dbcreate +mv /scripts/dbload.sh /dbload diff --git a/pluie/alpine/README.md b/pluie/alpine/README.md index fe0fe20..4127f55 100644 --- a/pluie/alpine/README.md +++ b/pluie/alpine/README.md @@ -1,5 +1,10 @@ # pluie/alpine +- [index][1] +- [image pluie/alpine-mysql][3] +- [image pluie/alpine-apache][4] +- [docker tips][5] + This Image provide a Linux Alpine distribution with : - fully functionnal & colorized terminal - bash @@ -79,5 +84,8 @@ EXPOSE 80 VOLUME /app ``` - - + [1]: https://github.com/pluie-org/docker-images + [2]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine + [3]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-mysql + [4]: https://github.com/pluie-org/docker-images/tree/master/pluie/alpine-apache + [5]: https://github.com/pluie-org/docker-images/blob/master/DOCKER.md diff --git a/pluie/alpine/files.tar b/pluie/alpine/files.tar index 9c9e5ff54e84f49788a5416f0f7ff0d0a306a6b6..0dcd9d4a15efee6a5d23eb292449c86d2dfb374f 100644 GIT binary patch delta 414 zcmZozz}T>WaY81e$;2!rK~p1h6LV8T1_MK5BSSL=1%t_sj47KL88es}O($oufE1XR z8yXma6d0Qu!WFPW6mY;4m;n_SnVA^F6>zpNOPH857#f+I8W3v?RhXN=Rq&QF zvLxrHq)sm5vk?R_Y?X`*jFh+(fFLzzawDJUqw~3hnB2=YOZ8kACL&(YhXIlI~Qw;## CXkXU= delta 391 zcmZozz}T>WaYE+gOgR||12YCgBXbiob5kQzQ$q#=Lt`T&0|o_y$&QREn;981m?vk7 z$ckeqGBGfPD`EvHQj--oKr_k6%+wgJh_i)R!pIn`0%(retjmYvQX2wQvy~?P1O@Xe3%c=ionk3gFhzK+jQxikDtUM?4WG*Qb SlTCr43zwJv&$PHfLk$4;a#xK2 diff --git a/pluie/alpine/util.sh b/pluie/alpine/util.sh index 3ec1c70..b96dd1b 100755 --- a/pluie/alpine/util.sh +++ b/pluie/alpine/util.sh @@ -2,14 +2,14 @@ # pluie/docker-images - a-Sansara (https://github.com/a-sansara) function bash_prompt() { - local Cenv="243" + local Cenvcode="243" if [ "$SHENV_CTX" = "INT" ]; then - local Cenv="202" + local Cenvcode="202" elif [ "$SHENV_CTX" = "PROD" ]; then - local Cenv="160" + local Cenvcode="160" fi local Cdate="\[\033[1;33m\]" - local Cctx="\[\033[1;48;5;243m\]" + local Cctx="\[\033[1;48;5;${Cenvcode}m\]" local Cname="\[\033[1;48;5;${SHENV_COLOR}m\]" local Cpath="\[\033[1;38;5;36m\]" local Cwhite="\[\033[1;38;5;15m\]"