読者です 読者をやめる 読者になる 読者になる

@Konboi memo

主に技術に関してつらつらと。

docker compose を使ってみた

はじめに

実際に docker-compose を使ってみた。

今回はsampleとしてredis-serverのコンテナとredis-clientのコンテナをそれぞれたて、 client側からserverへベンチをかけてみる。

設定

# docker-compose.yml
server:
  command: redis-server
  image: redis:2.8
client:
  image: redis:2.8
  command: redis-benchmark -h server -t set -n 10000 -r 100000
  links:
    - server

結果

$ docker-compose up
Creating dockercomposesample_server_1...
Pulling image redis:2.8...
Pulling repository redis
03887134769f: Download complete
21e4345e9035: Download complete
b3d362b23ec1: Download complete
29809ed33dfd: Download complete
b720af9a6508: Download complete
c215cb712b89: Download complete
8d9a45a71a91: Download complete
8da9d27ff257: Download complete
8bd3343cbfc6: Download complete
37f5dcde0b92: Download complete
50c44c3f8567: Download complete
6286474082db: Download complete
4d2be13a8d7c: Download complete
41bec594de38: Download complete
c95d0010b5d8: Download complete
5a0b2bd2db6b: Download complete
5992cb8c188e: Download complete
Status: Downloaded newer image for redis:2.8
Creating dockercomposesample_client_1...
Attaching to dockercomposesample_server_1, dockercomposesample_client_1
server_1 | [1] 20 May 09:25:26.467 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
server_1 |                 _._
server_1 |            _.-``__ ''-._
server_1 |       _.-``    `.  `_.  ''-._           Redis 2.8.20 (00000000/0) 64 bit
server_1 |   .-`` .-```.  ```\/    _.,_ ''-._
server_1 |  (    '      ,       .-`  | `,    )     Running in stand alone mode
server_1 |  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
server_1 |  |    `-._   `._    /     _.-'    |     PID: 1
server_1 |   `-._    `-._  `-./  _.-'    _.-'
server_1 |  |`-._`-._    `-.__.-'    _.-'_.-'|
server_1 |  |    `-._`-._        _.-'_.-'    |           http://redis.io
server_1 |   `-._    `-._`-.__.-'_.-'    _.-'
server_1 |  |`-._`-._    `-.__.-'    _.-'_.-'|
server_1 |  |    `-._`-._        _.-'_.-'    |
server_1 |   `-._    `-._`-.__.-'_.-'    _.-'
server_1 |       `-._    `-.__.-'    _.-'
server_1 |           `-._        _.-'
server_1 |               `-.__.-'
server_1 |
server_1 | [1] 20 May 09:25:26.472 # Server started, Redis version 2.8.20
server_1 | [1] 20 May 09:25:26.472 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for t
his to take effect.
server_1 | [1] 20 May 09:25:26.472 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' a
s root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
server_1 | [1] 20 May 09:25:26.472 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
server_1 | [1] 20 May 09:25:26.472 * The server is now ready to accept connections on port 6379
====== SET ======1856.68
client_1 |   10000 requests completed in 0.69 seconds                                                                                                                                                                                                                [26/2270]
client_1 |   50 parallel clients
client_1 |   3 bytes payload
client_1 |   keep alive: 1
client_1 |
client_1 | 46.05% <= 1 milliseconds

…
< 省略>
…

client_1 | 99.85% <= 88 milliseconds
client_1 | 100.00% <= 136 milliseconds
client_1 | 14409.22 requests per second
client_1 |
client_1 |
dockercomposesample_client_1 exited with code 0
Gracefully stopping... (press Ctrl+C again to force)
Stopping dockercomposesample_server_1...
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 810, in __bootstrap_inner
  File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 763, in run
  File "/compose/build/docker-compose/out00-PYZ.pyz/compose.cli.multiplexer", line 41, in _enqueue_output
  File "/compose/build/docker-compose/out00-PYZ.pyz/compose.cli.log_printer", line 62, in _make_log_generator
  File "/compose/build/docker-compose/out00-PYZ.pyz/compose.container", line 140, in wait
  File "/compose/build/docker-compose/out00-PYZ.pyz/docker.client", line 918, in wait
  File "/compose/build/docker-compose/out00-PYZ.pyz/docker.client", line 79, in _post
  File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 425, in post
  File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 383, in request
  File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 486, in send%

こんな感じで client側からserverに接続できた。

なんで redis-benchmark -h server で接続できるのか

というとclient側の/etc/hosts

172.17.1.11  b799fcf887da
127.0.0.1    localhost
::1          localhost ip6-localhost ip6-loopback
fe00::0      ip6-localnet
ff00::0      ip6-mcastprefix
ff02::1      ip6-allnodes
ff02::2      ip6-allrouters

172.17.1.9   dockercomposesample_server_1 f27c07cbc850
172.17.1.9   server f27c07cbc850 dockercomposesample_server_1
172.17.1.9   server_1 f27c07cbc850 dockercomposesample_server_1

が設定されているので server という値で接続できるようになっている。