66
63

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacでDockerをインストールした後に必要な作業

Posted at

MacでDockerをインストールしてあったのだけど、久しぶりに使おうとしたらコマンドを忘れてすぐに使えなかったので、ここにまとめておきます。
いざ、Dockerを使おうとdocker pull centosをしても

$ docker pull centos
Using default tag: latest
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
butada-mac:python_camera butada$ docker run hello-world
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
$

と表示されていまいました。
MacはLinuxカーネルが無いのでVMを立ててそこにDockerデーモンを起動させておく必要があるのを忘れていました。

環境

  • Mac OS X El Capitan
  • Docker version 1.10.1, build 9e83765

コマンド一覧

用途 コマンド
Docker用のVMを作成 docker-machine create --driver virtualbox default
環境変数を設定 eval $(docker-machine env default)
VM一覧を表示 docker-machine ls
Hello worldコンテナを実行 docker run hello-world
Docker用VMを再起動 docker-machine restart default

起動までの流れ

VirtualBoxでVMを用意しておく。

$ docker-machine create --driver virtualbox default2
Running pre-create checks...
Creating machine...
(default2) Copying /Users/butada/.docker/machine/cache/boot2docker.iso to /Users/butada/.docker/machine/machines/default2/boot2docker.iso...
(default2) Creating VirtualBox VM...
(default2) Creating SSH key...
(default2) Starting the VM...
(default2) Check network to re-create if needed...
(default2) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env default2

環境変数を設定する。

# eval $(docker-machine env default2)

ちなみに環境変数の中身はこちら。

$ docker-machine env default2
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:2376"
export DOCKER_CERT_PATH="/Users/butada/.docker/machine/machines/default2"
export DOCKER_MACHINE_NAME="default2"
# Run this command to configure your shell: 

マシン一覧を表示。

$ docker-machine ls
NAME       ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default2   -        virtualbox   Running   tcp://192.168.99.101:2376           v1.10.3   

Hello Worldを動作させ、コンテナが動作することを確認する。

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
03f4658f8b78: Pull complete 
a3ed95caeb02: Pull complete 
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
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.
 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

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/userguide/

これで動きましたね。
あとは、docker pull centosなどを実行できます。

参考

66
63
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
66
63

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?