2 wy18780215467 wy18780215467 于 2015.07.01 17:06 提问

Mac OS 下 Docker的配置问题

刚开始用docker ,
按照官网 上面的说明,配置了一下,但是没配成功,求解答,
下面是我进行的步骤(操作系统:Mac os)
1.到官网去下了个 boot2docker,安装后,然后运行application
2. 然后它 自动执行了一些 command,比如innit 和 start

bash
unset DYLD_LIBRARY_PATH ; unset LD_LIBRARY_PATH
mkdir -p ~/.boot2docker
if [ ! -f ~/.boot2docker/boot2docker.iso ]; then cp /usr/local/share/boot2docker/boot2docker.iso ~/.boot2docker/ ; fi
/usr/local/bin/boot2docker init 
/usr/local/bin/boot2docker up 
$(/usr/local/bin/boot2docker shellinit)
docker version
Last login: Wed Jul  1 15:09:55 on ttys005
wangyaos-MBP-4:~ wangyao$ bash
bash-3.2$ unset DYLD_LIBRARY_PATH ; unset LD_LIBRARY_PATH
bash-3.2$ mkdir -p ~/.boot2docker
bash-3.2$ if [ ! -f ~/.boot2docker/boot2docker.iso ]; then cp /usr/local/share/boot2docker/boot2docker.iso ~/.boot2docker/ ; fi
bash-3.2$ /usr/local/bin/boot2docker init 
Virtual machine boot2docker-vm already exists
bash-3.2$ /usr/local/bin/boot2docker up 
Waiting for VM and Docker daemon to start...
.............o
Started.
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/wangyao/.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/wangyao/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1

bash-3.2$ $(/usr/local/bin/boot2docker shellinit)
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/key.pem
bash-3.2$ docker version
Client version: 1.7.0
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 0baf609
OS/Arch (client): darwin/amd64
An error occurred trying to connect: Get https://192.168.59.103:2376/v1.19/version: x509: certificate is valid for 127.0.0.1, 10.0.2.15, not 192.168.59.103

3.然后我看官网上的 command ,执行 Hello world 的demo 。$ docker run hello-world ,但是执行不成功,结果如下

bash-3.2$ docker run hello-world
An error occurred trying to connect: Post https://192.168.59.103:2376/v1.19/containers/create: x509: certificate is valid for 127.0.0.1, 10.0.2.15, not 192.168.59.103


4.然后我执行 $ boot2docker shellinit 查看变量, 发现比官网上的变量要少来那么几个如下:
这是我的运行结果:

bash-3.2$ boot2docker shellinit
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/key.pem
Your environment variables are already set correctly.

这是官网上面的运行结果:

$ boot2docker shellinit
Writing /Users/mary/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/mary/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/mary/.boot2docker/certs/boot2docker-vm/key.pem
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=/Users/mary/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1

5.然后我就感觉好像是少了上述3个变量导致的问题,接着我尝试着添加这3个变量,然后再次查询变量,发现变量没有添加成功;

 bash-3.2$ export DOCKER_HOST=tcp://192.168.59.103:2376
bash-3.2$     export DOCKER_CERT_PATH=/Users/wangyao/.boot2docker/certs/boot2docker-vm
bash-3.2$     export DOCKER_TLS_VERIFY=1
bash-3.2$ boot2docker shellinit
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/key.pem
Your environment variables are already set correctly.

6.添加变量没有任何改变, 我又尝试着把DOCKER_HOST变量的端口号改变,然后神奇的事情发生了

bash-3.2$ export DOCKER_HOST=tcp://192.168.59.103:2375
bash-3.2$ boot2docker shellinit
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/wangyao/.boot2docker/certs/boot2docker-vm/key.pem
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=/Users/wangyao/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1

7.为毛我明明把端口号改成了2375 ,这里添加之后 变成了端口号2376 , 接着我又尝试了几遍,把端口号各种改,发现 :只要端口号是2376,就添加不成功,除此之外,变量可以添加成功,但是添加的端口号全尼玛是2376.。。。。。。。

8.执行上面command之后 , 好吧,我就当变量已经添加成功了,我再次执行Hello World的demo。结果如下(还是不成功)

bash-3.2$ docker run hello-world
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?

Csdn user default icon
上传中...
上传图片
插入图片