Skip to content

Commit

Permalink
Add prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
nanofi committed Oct 29, 2015
1 parent c0dc229 commit 547a9d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ To run it:
$ docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e MYSQL_ROOT_PASSWORD="password" nanofi/mysql
```
Start any containers with env vars:
- `DB_NAME`; database name
- `DB_USER`; username
- `DB_PASS`; password
- `MYSQL_DB_NAME`; database name
- `MYSQL_DB_USER`; username
- `MYSQL_DB_PASS`; password

If `DB_NAME` presences, the container creates a database. If `DB_NAME`, `DB_USER` and `DB_PASS` presence, the container creates an user which has all privilege to the database.
If `MYSQL_DB_NAME` presences, the container creates a database. If `MYSQL_DB_NAME`, `MYSQL_DB_USER` and `MYSQL_DB_PASS` presence, the container creates an user which has all privilege to the database.

8 changes: 4 additions & 4 deletions docker-mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func update(client *docker.Client) {
log.Fatalf("unable to create temp file: %s\n", err)
}
for _, container := range containers {
if val, ok := container.Env["DB_NAME"]; ok {
if val, ok := container.Env["MYSQL_DB_NAME"]; ok {
fmt.Fprintf(dest, "CREATE DATABASE IF NOT EXISTS %s ;\n", val)
}
}
for _, container := range containers {
user, okUser := container.Env["DB_USER"]
pass, okPass := container.Env["DB_PASS"]
db, okDb := container.Env["DB_NAME"]
user, okUser := container.Env["MYSQL_DB_USER"]
pass, okPass := container.Env["MYSQL_DB_PASS"]
db, okDb := container.Env["MYSQL_DB_NAME"]
address := container.Address
if okUser && okPass && okDb {
fmt.Fprintf(dest, "GRANT ALL ON %s.* TO '%s'@'%s' identified by '%s' ;\n", db, user, address, pass)
Expand Down

0 comments on commit 547a9d4

Please sign in to comment.