Created
May 31, 2014 21:11
-
-
Save gologo13/4787639cb2fb7b748d10 to your computer and use it in GitHub Desktop.
Dockerコンテナ内にmysqlサーバを立てる ref: http://qiita.com/gologo13/items/1bdba6085ec79153bf1a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DOCKER-VERSION 0.3.4 | |
FROM centos:6.4 | |
# ここは自由に変えてください | |
MAINTAINER Taro Tanaka | |
# パッケージインストール | |
RUN yum install -y mysql mysql-server | |
# mysqlサーバのセットアップ | |
RUN echo "NETWORKING=yes" > /etc/sysconfig/network | |
ADD ./setup.sql | |
RUN /usr/bin/mysqld_safe & \ | |
sleep 10s && \ | |
cat setup.sql | mysql | |
# 外部からmysqlサーバにアクセスできるように | |
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf | |
# ポート番号 3306 を外部に公開 | |
EXPOSE 3306 | |
CMD ["/usr/bin/mysqld_safe"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RUN echo "NETWORKING=yes" > /etc/sysconfig/network | |
ADD ./setup.sql ./setup.sql | |
RUN /usr/bin/mysqld_safe & \ | |
sleep 10s && \ | |
cat setup.sql | mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker build -t gologo13/mysql . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker run -i -p 3306:3306 -t gologo13/mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo docker run -i -p 3306:3306 -t gologo13/mysql /bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat mysql_client.sh | |
#!/bin/sh | |
# docker build 時に指定したタグ名 | |
TAG="gologo/mysql" | |
CONTAINER_ID=$(docker ps | grep $TAG | awk '{print $1}') | |
IP=$(docker inspect $CONTAINER_ID | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[0]["NetworkSettings"]["IPAddress"]') | |
# アカウントとパスワードは適宜変更してください | |
mysql -u admin -ppassword -h $IP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ chmod u+x mysql_client.sh | |
$ sudo mysql_client.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment