前提条件
- OS X: 10.10.3
- VirtualBox: 4.3.26
- Homebrew: 0.9.5
Boot2Docker install
Macでdockerを使うためHomebrewでboot2dockerをインストールする。
$ brew install boot2docker
Boot2Docker set up
boot2dockerのイメージを起動する。
$ boot2docker init
...
$ boot2docker up
Waiting for VM and Docker daemon to start...
.o
Started.
Writing /Users/shua/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/shua/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/shua/.boot2docker/certs/boot2docker-vm/key.pem
To connect the Docker client to the Docker daemon, please set:
export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH=/Users/shua/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1
$ export DOCKER_HOST=tcp://192.168.59.103:2376
$ export DOCKER_CERT_PATH=/Users/shua/.boot2docker/certs/boot2docker-vm
$ export DOCKER_TLS_VERIFY=1
MySQL Docker Container 起動
MySQLのDockerコンテナーを起動する。
$ docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d -p 13306:3306 mysql:5.6.24
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
14a48fd740d1 mysql:5.6.24 "/entrypoint.sh mysq 16 minutes ago Up 1 minutes 0.0.0.0:13306->3306/tcp test-mysql
MySQLクライアントをローカルマシンにインストール
$ brew install mysql
==> Installing mysql dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2a-1.yosemite.bottle.1.tar.
######################################################################## 100.0%
...
$ mysql --version
mysql Ver 14.14 Distrib 5.6.24, for osx10.10 (x86_64) using EditLine wrapper
接続
以下のようにすれば接続できる。boot2docker上でMySQLのDockerコンテナーが動いているので、接続先ホストはboot2dockerのVMホストにしておくこと。
$ mysql -h`boot2docker ip` -P13306 -uroot -pmy-secret-pw
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>