Mac OSXでDocker(インストール編)
公式サイト
Mac OS X - Docker Documentation
インストール
ダウンロードしたBoot2Docker-1.4.1.pkgを開くと、2ステップでboot2dockerツールのインストールは完了します。
ここまで5分。後は環境設定などをやっていきます。
初期化
boot2docker initで初期化を行います。公開鍵方式の鍵ペアを作成されました。
rsogo$ boot2docker init
Latest release for boot2docker/boot2docker is v1.4.1
Downloading boot2docker ISO image...
Success: downloaded https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso
to /Users/rsogo/.boot2docker/boot2docker.iso
Generating public/private rsa key pair.
Your identification has been saved in /Users/rsogo/.ssh/id_boot2docker.
Your public key has been saved in /Users/rsogo/.ssh/id_boot2docker.pub.
起動
Docker daemonを起動します。
rsogo$ boot2docker start
Waiting for VM and Docker daemon to start...
........................ooooooooooooooooooo
Started.
Writing /Users/rsogo/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/rsogo/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/rsogo/.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/rsogo/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1
環境変数等の設定
$(boot2docker shellinit)を($や()もそのまま)実行して、環境変数などをセットします。環境変数を直接.bashrcなどに書くのではなく、このコマンドが実行されるように設定するのが推奨されています。
rsogo$ $(boot2docker shellinit)
Writing /Users/rsogo/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/rsogo/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/rsogo/.boot2docker/certs/boot2docker-vm/key.pem
サンプルの実行
ここまでで準備はできたみたいなので、hello-worldというサンプルがあるのでそれを実行してみます。
rsogo$ docker run hello-world
Unable to find image 'hello-world:latest' locally
hello-world:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete
7fa0dcdc88de: Pull complete
ef872312fe1b: Pull complete
Status: Downloaded newer image for hello-world:latest
Hello from Docker.
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(Assuming it was not already locally available.)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
For more examples and ideas, visit:
http://docs.docker.com/userguide/
出力された内容を見ると、ローカルにないから、hello-worldのイメージをDocker Hubからダウンロードしています。 その後、"Hello from Docker"という文字列が表示されました。
このエラーが出るときは環境変数の初期化ができていない
rsogo$ docker run hello-world
FATA[0000] Post http:///var/run/docker.sock/v1.16/containers/create: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?