まずはhomebrewを最新にして、検索。ちゃんと出てきた。
$ brew update $ brew search dockertoolbox Caskroom/cask/dockertoolbox
homebrewでdockertoolboxをインストール。
一緒にvirtualboxもインストールされた。
LaunchpadにインストールされたvirtualboxとDocker Quickstart TerminalとKitematicが配置されている。
$ brew install Caskroom/cask/dockertoolbox ==> Installing brew-cask from caskroom/homebrew-cask Error: brew-cask-0.55.0 already installed To install this version, first `brew unlink brew-cask' ==> brew cask install Caskroom/cask/dockertoolbox ==> Satisfying dependencies ==> Installing Cask dependencies: virtualbox virtualbox ... ==> Downloading http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0.10-104061-OSX.dmg ######################################################################## 100.0% ==> Running installer for virtualbox; your password may be necessary. ==> Package installers may write to any location; options such as --appdir are ignored. Password: ==> installer: Package name is Oracle VM VirtualBox ==> installer: Installing at base path / ==> installer: The install was successful. 🍺 virtualbox staged at '/opt/homebrew-cask/Caskroom/virtualbox/5.0.10-104061' (4 files, 87M) done complete ==> Downloading https://github.com/docker/toolbox/releases/download/v1.9.0d/DockerToolbox-1.9.0d.pkg ######################################################################## 100.0% ==> Running installer for dockertoolbox; your password may be necessary. ==> Package installers may write to any location; options such as --appdir are ignored. ==> installer: Package name is Docker Toolbox ==> installer: Installing at base path / ==> installer: The install was successful. 🍺 dockertoolbox staged at '/opt/homebrew-cask/Caskroom/dockertoolbox/1.9.0d' (204M)
まずはdockerを動かすホストマシンをvirtualboxに設定して作成。
$ docker-machine create --driver virtualbox default Creating CA: /Users/xxx/.docker/machine/certs/ca.pem Creating client certificate: /Users/xxx/.docker/machine/certs/cert.pem Running pre-create checks... Creating machine... Waiting for machine to be running, this may take a few minutes... Machine is running, waiting for SSH to be available... Detecting operating system of created instance... Provisioning created instance... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... To see how to connect Docker to this machine, run: docker-machine env default
作成したものはここにファイルが作られるようです
$ ls -al ~/.docker/machine/machines/default/ total 81344 drwx------ 13 xxx staff 442 11 17 12:23 . drwx------ 3 xxx staff 102 11 17 12:22 .. -rw-r--r-- 1 xxx staff 31457280 11 17 12:22 boot2docker.iso -rw-r--r-- 1 xxx staff 1038 11 17 12:23 ca.pem -rw-r--r-- 1 xxx staff 1074 11 17 12:23 cert.pem -rw------- 1 xxx staff 2943 11 17 12:24 config.json drwx------ 5 xxx staff 170 11 17 12:23 default -rw------- 1 xxx staff 10158080 11 17 12:25 disk.vmdk -rw------- 1 xxx staff 1679 11 17 12:22 id_rsa -rw------- 1 xxx staff 381 11 17 12:22 id_rsa.pub -rw------- 1 xxx staff 1679 11 17 12:23 key.pem -rw------- 1 xxx staff 1675 11 17 12:23 server-key.pem -rw-r--r-- 1 xxx staff 1123 11 17 12:23 server.pem
docker-machineの状態を見てみると、起動しているようです。
$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM default - virtualbox Running tcp://192.168.99.100:2376
次に以下のコマンドを実行する。特に何も表示はされません。
$ eval "$(docker-machine env default)"
続いてredisのコンテナイメージを持ってきます。
$ docker pull redis:3.0.5 3.0.5: Pulling from library/redis 141ed44bf003: Pull complete e2e4a15f0f05: Pull complete bde7d1a2c3f2: Pull complete 30fde03bce2b: Pull complete 57f91d220af6: Pull complete 85decd8581c3: Pull complete dc733a1e5ab9: Pull complete 9702d439a536: Pull complete 1f7c80b73750: Pull complete f947b6a7c248: Pull complete 9dc7228b2288: Pull complete 53ba438d7aa7: Pull complete fad954217030: Pull complete a06a2b579a40: Pull complete 05239cc42ab0: Pull complete fd59e10ac3c9: Pull complete 7159515e5dce: Pull complete Digest: sha256:5b408fc3c12a800ca36ca243f9bdcc3f8efed8608572a509b7fbdcbef3e76b8c Status: Downloaded newer image for redis:3.0.5
Dockerfileを作成します。
FROM redis:3.0.5 # log file RUN touch /var/log/redis.log && chmod 755 /var/log/redis.log && chown redis:redis /var/log/redis.log # conf file ADD redis.conf /tmp/redis.conf RUN mkdir -p -m 755 /usr/local/etc/redis && chown redis:redis /usr/local/etc/redis && cp /tmp/redis.conf /usr/local/etc/redis && chown redis:redis /usr/local/etc/redis/redis.conf && rm /tmp/redis.conf EXPOSE 6379 CMD ["redis-server","/usr/local/etc/redis/redis.conf"]
redis.confも同じディレクトリに配置します。
vim redis.conf 適切な内容を記述
コンテナイメージを作成します。
$ docker build -t redis:3.0.5 . Sending build context to Docker daemon 44.54 kB Step 1 : FROM redis:3.0.5 ---> 7159515e5dce Step 2 : RUN touch /var/log/redis.log && chmod 755 /var/log/redis.log && chown redis:redis /var/log/redis.log ---> Running in afdf261202ed ---> 779d22d0e041 Removing intermediate container afdf261202ed Step 3 : ADD redis.conf /tmp/redis.conf ---> 69591881edca Removing intermediate container d64a9c967b0f Step 4 : RUN mkdir -p -m 755 /usr/local/etc/redis && chown redis:redis /usr/local/etc/redis && cp /tmp/redis.conf /usr/local/etc/redis && chown redis:redis /usr/local/etc/redis/redis.conf && rm /tmp/redis.conf ---> Running in 9304d5f32d59 ---> 250ea953a1a9 Removing intermediate container 9304d5f32d59 Step 5 : EXPOSE 6379 ---> Running in 2d3f10877d3b ---> bec30d81d359 Removing intermediate container 2d3f10877d3b Step 6 : CMD redis-server /usr/local/etc/redis/redis.conf ---> Running in 28d5ce42be84 ---> e5d21ff31a69 Removing intermediate container 28d5ce42be84 Successfully built e5d21ff31a69
コンテナを起動する。
Unable to findとか言われてるので怪しいのだが、
ちゃんと起動していた。。。
$ docker run -d --name redis_server redis:3.0.5 Unable to find image 'redis:3.0.5' locally 3.0.5: Pulling from library/redis 141ed44bf003: Pull complete e2e4a15f0f05: Pull complete bde7d1a2c3f2: Pull complete 30fde03bce2b: Pull complete 57f91d220af6: Pull complete 85decd8581c3: Pull complete dc733a1e5ab9: Pull complete 9702d439a536: Pull complete 1f7c80b73750: Pull complete f947b6a7c248: Pull complete 9dc7228b2288: Pull complete 53ba438d7aa7: Pull complete fad954217030: Pull complete a06a2b579a40: Pull complete 05239cc42ab0: Pull complete fd59e10ac3c9: Pull complete 7159515e5dce: Pull complete Digest: sha256:5b408fc3c12a800ca36ca243f9bdcc3f8efed8608572a509b7fbdcbef3e76b8c Status: Downloaded newer image for redis:3.0.5 ea875fae4d9d6c70b8a4393b5d2dff0795776b3fa21eb929628d68d5b602432c
コンテナが起動していることを確認。
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2d17e74d25e2 redis:3.0.5 "/entrypoint.sh redis" 14 minutes ago Up 14 minutes 6379/tcp redis_server
redisに接続するため、接続するIPを調べる
$ docker-machine ip default 192.168.99.100
telnetで接続してみたら繋がらなかった
$ telnet telnet> open 192.168.99.100 6379 Trying 192.168.99.100... telnet: connect to address 192.168.99.100: Connection refused telnet: Unable to connect to remote host telnet> quit
コンテナを停止して削除し、ポートを指定してコンテナを再度作り直す
$ docker stop redis_server redis_server $ docker rm redis_server redis_server $ docker run -d --name redis_server -p 6379:6379 redis:3.0.5 f59a2531a0c46a780b78084c7e0b75508750d472532df62ff44b62305613d45a $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f59a2531a0c4 redis:3.0.5 "/entrypoint.sh redis" 3 seconds ago Up 2 seconds 0.0.0.0:6379->6379/tcp redis_server
今度はtelnetで接続できた
$ telnet telnet> open 192.168.99.100 6379 Trying 192.168.99.100... Connected to 192.168.99.100. Escape character is '^]'. INFO $2067 # Server redis_version:3.0.5 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:b26e24044465030c redis_mode:standalone os:Linux 4.1.12-boot2docker x86_64 arch_bits:64 multiplexing_api:epoll gcc_version:4.7.2 process_id:1 run_id:23e122e716026918b41998ce6cec3a4af9590fe6 tcp_port:6379 uptime_in_seconds:178 uptime_in_days:0 hz:10 lru_clock:4902862 config_file:/usr/local/etc/redis/redis.conf # Clients connected_clients:1 client_longest_output_list:0 client_biggest_input_buf:0 blocked_clients:0 # Memory used_memory:296832 used_memory_human:289.88K used_memory_rss:9207808 used_memory_peak:296832 used_memory_peak_human:289.88K used_memory_lua:36864 mem_fragmentation_ratio:31.02 mem_allocator:jemalloc-3.6.0 # Persistence loading:0 rdb_changes_since_last_save:0 rdb_bgsave_in_progress:0 rdb_last_save_time:1447743260 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:-1 rdb_current_bgsave_time_sec:-1 aof_enabled:1 aof_rewrite_in_progress:0 aof_rewrite_scheduled:0 aof_last_rewrite_time_sec:-1 aof_current_rewrite_time_sec:-1 aof_last_bgrewrite_status:ok aof_last_write_status:ok aof_current_size:0 aof_base_size:0 aof_pending_rewrite:0 aof_buffer_length:0 aof_rewrite_buffer_length:0 aof_pending_bio_fsync:0 aof_delayed_fsync:0 # Stats total_connections_received:1 total_commands_processed:0 instantaneous_ops_per_sec:0 total_net_input_bytes:6 total_net_output_bytes:0 instantaneous_input_kbps:0.00 instantaneous_output_kbps:0.00 rejected_connections:0 sync_full:0 sync_partial_ok:0 sync_partial_err:0 expired_keys:0 evicted_keys:0 keyspace_hits:0 keyspace_misses:0 pubsub_channels:0 pubsub_patterns:0 latest_fork_usec:0 migrate_cached_sockets:0 # Replication role:master connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0 # CPU used_cpu_sys:0.17 used_cpu_user:0.18 used_cpu_sys_children:0.00 used_cpu_user_children:0.00 # Cluster cluster_enabled:0 # Keyspace
参考URL
https://docs.docker.com/v1.8/installation/mac/
https://blog.docker.com/2015/08/docker-toolbox/
http://qiita.com/rubytomato@github/items/dd2e605706b03ad60f00
0 件のコメント:
コメントを投稿