Skip to content

Instantly share code, notes, and snippets.

@mistymagich
Last active September 1, 2015 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mistymagich/264955e652db26a8c240 to your computer and use it in GitHub Desktop.
Save mistymagich/264955e652db26a8c240 to your computer and use it in GitHub Desktop.
Sample to running a custom SQL in "Docker Official MySQL Image"
web:
image: corbinu/docker-phpmyadmin
ports:
- "80:80"
links:
- mysql:mysql
environment:
MYSQL_USERNAME: root
mysql:
image: mysql
volumes:
- ./initdb.d:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: mysqlpassword
MYSQL_USER: "example_user"
MYSQL_PASSWORD: "example_pass"
MYSQL_DATABASE: "example"
ports:
- "3306:3306"
#!/bin/bash -eu
mysql=( mysql --protocol=socket -uroot -p"${MYSQL_ROOT_PASSWORD}" )
"${mysql[@]}" <<-EOSQL
CREATE DATABASE IF NOT EXISTS another_db;
GRANT ALL ON another_db.* TO '${MYSQL_USER}'@'%' ;
EOSQL
CREATE TABLE IF NOT EXISTS `example`.`sample` (
`id` INT UNSIGNED NOT NULL,
`name` VARCHAR(255) NOT NULL,
`created_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment