Docker:墙内的基本使用

本文介绍了在Docker被墙的情况下,如何通过国内镜像下载image,并详细讲述了启动Docker daemon的方法,包括设置代理和解决无法连接的问题。还分享了如何导入并使用下载的Ubuntu image。

这几天因为index.docker.io被墙无法下载image的原因,一直在找别的玩法。试了一下国内镜像,龟速并且认证繁琐。从其他地方直接down了一个image,终于可以玩起来了。

1.文件系统
docker是个基于Linux容器的产品,内部文件系统基本与linux常见构造相同,docker启动后Termpro和WinSCP等照常使用,连接信息如下:

IP:192.168.59.103
User:docker
Pswd:tcuser

2.boot2docker的玩法
像我从这么低端开始玩boot2docker的比较少,因此资料也不是很好找,记录一下遇到的问题。

启动docker以后,运行一个应用,出现以下错误:

$ sudo docker run hello-world FATA[0000] Cannot connect to the Docker daemon.
Is ‘docker -d’ running on this host?

Docker daemon守护进程默认不启动,这也蛮奇葩的,通常也会导致上面的Termpro和WinSCP无法连接,按照提示启动deamon:

$ sudo HTTP_PROXY=http://proxy.host:port/ docker -d
INFO[0000] +job serveapi(unix:///var/run/docker.sock)
INFO[0000] +job init_networkdriver()
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)
INFO[0000] -job init_networkdriver() = OK (0)
INFO[0000] Loading containers: start. ……..
INFO[0000] Loading containers: done.
INFO[0000] docker daemon: 1.5.0 a8a31ef; execdriver: native-0.2; graphdriver: au fs
INFO[0000] +job acceptconnections()
INFO[0000] -job acceptconnections() = OK (0)

执行以后这个窗口变成了一个记录deamon日志的窗口,不可以输入,重开Termpro连接192.168.59.103。
另外,在守护进程中设置一下代理,在连接国内镜像时是必要的。但是在本地搭建私服docker-registry时注意去掉。
在Termpro中再次运行应用:

docker@boot2docker:~$ sudo docker run hello-world
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/

这个没啥问题,开始进阶版,要尝试点更高级的。

docker@boot2docker:~$ sudo docker search ubuntu14
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 44 [OK]
sktelecom/ubuntu14.10-hdw 2 [OK]
sandersliu/ubuntu14 1 [OK]
ushios/ubuntu14-apache-php 0 [OK]
…….
eos87/ubuntu14-phantomjs 0 [OK]

找是找到了不少,问题是没法下下来,我在这个地址下了一个ubuntu的image:
http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64.tar.gz
测试可用,把它导入docker:首先用WinSCP把它传到/home/docker下,然后运行以下命令:

cat ubuntu-14.04-x86_64.tar.gz |docker import - ubuntu:ubuntu14

很快就能完成,完成后查看自己的image:

docker@boot2docker:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              ubuntu14            b4e7bd2f150a        3 hours ago         415.6 MB
hello-world         latest              e45a5af57b00        11 weeks ago        910 B

成功导入了ubuntu,这样我们就可以在docker中运行出一个自己的ubuntu了。

docker run -i -t ubuntu:ubuntu14 /bin/bash

以上运行后,进入了该ubuntu的bash环境。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值