$ 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なのでレスポンスタイム分布の取得をやってみましょう。
$ docker run -it --link mysql55:mysql --rm mysql:5.5 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.5.51 MySQL Community Server (GPL)
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 | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec)
mysql> select Host, User from mysql.user; +------+------+ | Host | User | +------+------+ | % | root | +------+------+ 1 row in set (0.00 sec)
RUN apt-get update && apt-get install locales -y && localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias ja_JP.UTF-8 ENV LANG ja_JP.utf8 公式イメージにはlocalesが入っていなかったのでlocaledefの前にapt-getで導入するようにしました。
日本語化されたイメージ、mysql_jp:5.5を作ります。
$ docker build -t mysql_jp:5.5 ./ 確認
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql_jp 5.5 42465a1c94d5 22 minutes ago 284.5 MB 設定ファイルの調整/etc/mysql/conf.d/ にバインドするディレクトリconf.dを作成して追加の設定を書いたcnfファイルを置きます。
CREATE TABLE foodb.users (id int , name varchar(255)); GRANT ALL ON foodb.users TO foo; INSERT INTO foodb.users (id, name) VALUES (1, 'first'), (1, 'second') foodbデータベースにusersテーブルを作成しユーザーfooに権限を与え、usersテーブルに初期値をINSERT文で投入というシナリオです。
mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" $MYSQL_DATABASE <<-EOSQL CREATE TABLE users (id int , name varchar(255)); EOSQL このようなスクリプトでテーブル作成は行われるのですがshスクリプト実行後にコンテナがExitしてしまうという症状が発生。解決出来ずにハマりまくり、sqlファイルでの初期化に方針変更しました。
$ docker run -it --rm --link postgres96beta4:postgres postgres:9.6 psql -h postgres -U postgres Password for user postgres: psql (9.6beta4) Type "help" for help.
postgres=# select version(); version --------------------------------------------------------------------------------------------- PostgreSQL 9.6beta4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit (1 row)
$ psql -h localhost -p 15432 -U postgres Password for user postgres: psql (9.3.5, server 9.6beta4) WARNING: psql major version 9.3, server major version 9.6. Some psql features might not work. Type "help" for help.
$ docker exec -it postgres96beta4 bash root@d2e991bd61a7:/# cd /var/lib/postgresql/data/ root@d2e991bd61a7:/var/lib/postgresql/data# more postgresql.conf と、このようにpostgresql.confを眺めてみたり(lessもviもなかった)。
root@d2e991bd61a7:/var/lib/postgresql/data# more pg_hba.conf pg_hba.confを眺めてみたり。pg_hba.confから抜粋しますと
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust
host all all 0.0.0.0/0 md5 ローカルからはtrustで他はパスワード認証ですかね。
RUN localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias ja_JP.UTF-8 ENV LANG ja_JP.utf8 日本語化されたイメージ、mypostgres:9.6を作ります。
$ docker build -t mypostgres:9.6 ./ 確認
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE mypostgres 9.6 4b7ea9f892dd 24 seconds ago 269.2 MB データベースの初期化操作しているディレクトリに/docker-entrypoint-initdb.d対応用にinitdbというディレクトリを作成しました。postgres/9.6/docker-entrypoint.sh を読んでみたところ
for f in /docker-entrypoint-initdb.d/*; do case "$f" in *.sh) echo "$0: running $f"; . "$f" ;; *.sql) echo "$0: running $f"; "${psql[@]}" < "$f"; echo ;; *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;; *) echo "$0: ignoring $f" ;; esac echo done で順次処理となっているのでファイル名順に実行されるようです。sqlをgzip圧縮したsql.gz拡張子のファイルにも対応しているようですね。
初期化時にdockerユーザーとdockerテーブルを作成するshを作成します。
initdb/01adduser.sh
#!/bin/bash set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL CREATE USER docker; ALTER USER docker WITH PASSWORD 'dockerpassword'; CREATE DATABASE docker; GRANT ALL PRIVILEGES ON DATABASE docker TO docker; EOSQL 次にsqlファイル内で\cでデータベースとユーザーをdockerに切り替えてテーブルを作ってみます。shでdb接続からしたほうが簡単な気がしますが、実験です。
initdb/02createtb.sql
\c docker docker
CREATE TABLE auth_group ( id integer NOT NULL, name character varying(80) NOT NULL );
COPY auth_group (id, name) FROM stdin; 1 Gyoumu 2 Master 3 System \. 日本語化したmypostgres:9.6からMacのinitdbディレクトリを/docker-entrypoint-initdb.dにバインドしてコンテナを起動します。
でも Bazaar Explorer を起動できたので大丈夫だと思っていた、まだ幸せだった、あの頃。
地獄変
盆休み明けにコードの編集始めようリポジトリを選択したら Bazaar Explorer がぶち落ちやがった。
$ bzr explorer QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files 〜 250行位略 〜 QKqueueFileSystemWatcherEngine::addPaths: open: Too many open files QEventDispatcherUNIXPrivate(): Unable to create thread pipe: Too many open files QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe zsh: abort bzr explorer
Traceback (most recent call last): File "/Library/Python/2.6/site-packages/bzrlib/commands.py", line 930, in exception_to_return_code return the_callable(*args, **kwargs) File "/Library/Python/2.6/site-packages/bzrlib/commands.py", line 1141, in run_bzr ret = run(*run_argv) File "/Library/Python/2.6/site-packages/bzrlib/commands.py", line 673, in run_argv_aliases return self.run(**all_cmd_args) File "/Library/Python/2.6/site-packages/bzrlib/commands.py", line 697, in run return self._operation.run_simple(*args, **kwargs) File "/Library/Python/2.6/site-packages/bzrlib/cleanup.py", line 136, in run_simple self.cleanups, self.func, *args, **kwargs) File "/Library/Python/2.6/site-packages/bzrlib/cleanup.py", line 166, in _do_with_cleanups result = func(*args, **kwargs) File "/Library/Python/2.6/site-packages/bzrlib/commands.py", line 1158, in ignore_pipe result = func(*args, **kwargs) File "/Library/Python/2.6/site-packages/bzrlib/builtins.py", line 2895, in run Logger(b, rqst).show(lf) File "/Library/Python/2.6/site-packages/bzrlib/log.py", line 382, in show self._show_body(lf) File "/Library/Python/2.6/site-packages/bzrlib/log.py", line 412, in _show_body lf.log_revision(lr) File "/Library/Python/2.6/site-packages/bzrlib/log.py", line 1558, in log_revision lines.extend(self.custom_properties(revision.rev)) File "/Library/Python/2.6/site-packages/bzrlib/log.py", line 1476, in custom_properties lines = self._foreign_info_properties(revision) File "/Library/Python/2.6/site-packages/bzrlib/log.py", line 1498, in _foreign_info_properties foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id) File "/Library/Python/2.6/site-packages/bzrlib/foreign.py", line 185, in parse_revision_id foreign_vcs = self.get(revid.split("-")[0]) File "/Library/Python/2.6/site-packages/bzrlib/registry.py", line 177, in get return self._dict[self._get_key_or_default(key)].get_obj() File "/Library/Python/2.6/site-packages/bzrlib/registry.py", line 74, in get_obj self._obj = get_named_object(self._module_name, self._member_name) File "/Library/Python/2.6/site-packages/bzrlib/pyutils.py", line 51, in get_named_object obj = __import__(module_name, {}, {}, from_list) File "/Library/Python/2.6/site-packages/bzrlib/plugins/svn/mapping.py", line 23, in from subvertpy import properties File "/Library/Python/2.6/site-packages/subvertpy/__init__.py", line 130, in raise ImportError("Unable to load subvertpy extensions: %s" % e) ImportError: Unable to load subvertpy extensions: dlopen(/Library/Python/2.6/site-packages/subvertpy/repos.so, 2): Symbol not found: _svn_fs__path_change2_create Referenced from: /usr/lib/libsvn_fs-1.0.dylib Expected in: /usr/local/lib/libsvn_fs_util-1.0.dylib in /usr/lib/libsvn_fs-1.0.dylib
*** Bazaar has encountered an internal error. This probably indicates a bug in Bazaar. You can help us fix it by filing a bug report at https://bugs.launchpad.net/bzr/+filebug including this traceback and a description of the problem.
中央リポジトリは Subversion なので死活問題。
解決編
bzr-svn 先に解決したのは bzr-svn。こいつのエラーが原因で explorer も落ちてるのかも?と思っていたので(違ったのですが)先に対処しました。
$ bzr commit Committing to: svn+http://###.###.###.###/##/####### modified app/controllers/jobs_controller.php /Library/Python/2.6/site-packages/bzrlib/plugins/svn/commit.py:252: DeprecationWarning: bzrlib.revisiontree.InventoryRevisionTree._get_inventory was deprecated in version 2.5.0. for child_name, child_ie in base_tree.inventory[file_id].children.iteritems(): /Library/Python/2.6/site-packages/bzrlib/plugins/svn/commit.py:703: DeprecationWarning: bzrlib.revisiontree.InventoryRevisionTree._get_inventory was deprecated in version 2.5.0. return self.old_tree.inventory[file_id] /Library/Python/2.6/site-packages/bzrlib/plugins/svn/commit.py:685: DeprecationWarning: bzrlib.revisiontree.InventoryRevisionTree._get_inventory was deprecated in version 2.5.0. old_ie = self.old_tree.inventory[file_id] /Library/Python/2.6/site-packages/bzrlib/plugins/svn/commit.py:303: DeprecationWarning: bzrlib.revisiontree.InventoryRevisionTree._get_inventory was deprecated in version 2.5.0. base_tree.inventory[child_ie.file_id].parent_id != child_ie.parent_id): /Library/Python/2.6/site-packages/bzrlib/plugins/svn/commit.py:364: DeprecationWarning: bzrlib.revisiontree.InventoryRevisionTree._get_inventory was deprecated in version 2.5.0. base_tree.inventory[child_ie.file_id].parent_id != child_ie.parent_id): Committed revision 83.