$ docker volume ls DRIVER VOLUME NAME local 17e11ebb9fc56e18d99b175d77b0c37b90da561bff07d601279ab7bfc0b0f414 local test-volume と言った感じでデータボリュームがホスト上に出来ます。 ランダム文字列な名前のほうは前記docker runのように名前未指定な場合によろしくやってくれてるわけです。問題なのが、コンテナを削除しても基本的にこれが残るってこと。
$ docker-compose up -d Creating mariadb-datastore Creating mariadb-db 起動状態の確認。
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ad95de15a67a mariadb_jp:10.1 "docker-entrypoint.sh" About a minute ago Up About a minute 0.0.0.0:23306->3306/tcp mariadb-db 3515029a71b5 busybox "sh" About a minute ago Exited (0) About a minute ago mariadb-datastore Sequel Pro を使いポートフォワードした23306にユーザーfooでfoodbデータベースに接続して初期化スクリプトが動作していることを確認できました。
クライアントコンテナでの接続用に作成したclientスクリプトを調整。
client
docker run -it --link mariadb-db:mysql --rm mariadb_jp:10.1 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' 接続して動作確認します。
$ ./client Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 10.1.16-MariaDB-1~jessie mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | foodb | | information_schema | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec)
MariaDB [(none)]> select Host, User from mysql.user; +------+------+ | Host | User | +------+------+ | % | foo | | % | root | +------+------+ 2 rows in set (0.00 sec)
MariaDB [(none)]> USE foodb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed MariaDB [foodb]> SHOW TABLES; +-----------------+ | Tables_in_foodb | +-----------------+ | users | +-----------------+ 1 row in set (0.00 sec)
MariaDB [foodb]> SELECT * from users; +------+--------+ | id | name | +------+--------+ | 1 | first | | 1 | second | +------+--------+ 2 rows in set (0.00 sec)
$ docker-compose up -d Creating percona-datastore Creating percona-db 起動状態の確認。
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b39630e2fd38 percona_jp:5.7 "docker-entrypoint.sh" 35 seconds ago Up 33 seconds 0.0.0.0:33306->3306/tcp percona-db ea4c9a0a21b5 busybox "sh" 35 seconds ago Exited (0) 34 seconds ago percona-datastore Sequel Pro を使いポートフォワードした33306にユーザーfooでfoodbデータベースに接続して初期化スクリプトが動作していることを確認できました。
クライアントコンテナでの接続用に作成したclientスクリプトを調整。
client
docker run -it --link percona-db:mysql --rm percona_jp:5.7 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' 接続して動作確認します。
$ ./client mysql: [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 6 Server version: 5.7.13-6 Percona Server (GPL), Release '6', Revision 'e3d58bb'
Copyright (c) 2009-2016 Percona LLC and/or its affiliates Copyright (c) 2000, 2016, 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> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | foodb | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
mysql> select Host, User from mysql.user; +------+------+ | Host | User | +------+------+ | % | foo | | % | root | +------+------+ 2 rows in set (0.00 sec) せっかくのPercona Serverなのでレスポンスタイム分布の取得をやってみましょう。
#展開したRoundcubeのディレクトリで $ php -S localhost:8000 PHP 5.5.14 Development Server started at Mon Sep 22 17:13:54 2014 Listening on http://localhost:8000 Document root is /Users/murave/roundcubemail-1.0.2 Press Ctrl-C to quit.