docker-images/pluie/alpine-mysql/README.md

132 lines
3.1 KiB
Markdown
Raw Normal View History

2016-07-28 13:26:22 +00:00
# pluie/alpine-mysql
- [index][1]
- [image pluie/alpine][2]
- [image pluie/alpine-apache][4]
- [docker tips][5]
2016-07-28 13:26:22 +00:00
Extend pluie/alpine with mysql (mariadb) 5.5.47
Project comes with various scripts to execute basic tasks such as :
- dbcreate
- dbdump
- dbload
If database directory is empty a root user is created at startup.
Root access to database is only permit on localhost
2016-07-28 13:26:22 +00:00
2016-07-28 15:46:03 +00:00
## Image Size
2016-07-28 13:26:22 +00:00
2016-07-29 13:25:39 +00:00
- image ~ 172 MB
2016-07-28 13:26:22 +00:00
2016-07-28 15:46:03 +00:00
## Image Volumes
2016-07-28 13:26:22 +00:00
```
/var/lib/mysql # mysql database directory
/dump # directory to store various mysql scripts
```
2016-07-28 13:26:22 +00:00
2016-07-28 15:46:03 +00:00
## ENV variables
2016-07-28 13:26:22 +00:00
```
MYSQL_DATABASE # create specified database at startup
MYSQL_USER # create specified user at startup (and grant all rights to MYSQL_DATABASE)
MYSQL_PASSWORD
MYSQL_ROOT_PASSWORD # don't really need it. a random root password is generated if none
```
2016-07-28 13:26:22 +00:00
### Inherit ENV variables
```
SHENV_CTX=LOCAL # LOCAL|INT|PROD change context bg color
SHENV_NAME=Mysql # container name
SHENV_COLOR=97 # ANSI EXTENDED COLOR CODE
```
2016-07-28 13:26:22 +00:00
2016-07-28 15:46:03 +00:00
## Image Usage
2016-07-28 13:26:22 +00:00
for example to start a new project :
2016-07-28 13:26:22 +00:00
```
$ cd /home/docker;
$ mkdir -p db/{mysql,dump}
$ docker run --name mysql \
-v $(pwd)/db/mysql:/var/lib/mysql \
-v $(pwd)/db/dump:/dump \
-e MYSQL_DATABASE=mybase \
-e MYSQL_USER=dev \
-e MYSQL_PASSWORD=mysql \
-it pluie/alpine-mysql
2016-07-28 13:26:22 +00:00
```
you don't need to expose your localhost mysql port.
for example :
2016-07-28 13:26:22 +00:00
```
$ docker run --name pma -p 8080:80 --link mysql:db -d phpmyadmin/phpmyadmin
```
and phpmyadmin is accessible via http://localhost:8080/ and linked to your mysql container
### Existing Scripts
2016-07-28 13:26:22 +00:00
create a new database with full rights to a user :
2016-07-28 13:26:22 +00:00
```
$ docker exec -it mysql /dbcreate mydbname myuser
2016-07-28 13:26:22 +00:00
```
load an export file in particular database :
2016-07-28 13:26:22 +00:00
```
$ docker exec -it mysql /dbload mydbname /dump/mydbname.init.sql
2016-07-28 13:26:22 +00:00
```
dump a database :
2016-07-28 13:26:22 +00:00
```
$ docker exec -it mysql /dbdump mydbname
2016-07-28 13:26:22 +00:00
```
### More specific actions as user
2016-07-28 13:26:22 +00:00
to connect to the mysql server as user from host :
2016-07-28 13:26:22 +00:00
```
mysql -h ipmysqlcontainer -udev -pmysql
```
to retriew container ip you can run first :
2016-07-28 13:26:22 +00:00
```
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql
2016-07-28 13:26:22 +00:00
```
to connect to the mysql server as user from container :
```
$ docker exec -it mysql "mysql -udev -pmysql"
```
### More specific actions as root
to connect to the mysql server as root :
```
$ docker exec -it mysql "mysql -uroot"
```
to connect to the mysql container as root :
```
docker exec -it mysql bash
```
then
```
$ mysql -uroot mybase < /dump/init.mybase.sql
$ mysqldump -uroot mybase > /dump/last.mybase.dump.sql
```
etc.
2016-07-28 13:26:22 +00:00
2016-07-28 15:46:03 +00:00
## Link Container
2016-07-28 13:26:22 +00:00
to link this container to another, use the default docker behavior
(as the example provide with phpmyadmin) :
2016-07-28 13:26:22 +00:00
```
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