Docker目前支持很多Gnu/Linux平台,使用较多的是Ubuntu与RHEL平台。本文使用作者小白的Ubuntu PC来演示如何安装docker。
$ sudo apt-get update $ sudo apt-get install docker.io
安装完毕,启动docker,
$ sudo service docker.io start $ sudo docker info Containers: 18 Images: 12 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Dirs: 60 Execution Driver: native-0.2 Kernel Version: 3.13.0-55-generic WARNING: No swap limit support
然后,使用ifconfig再看一下本机的IP信息,系统里会多出一个docker0的网卡,
$ ifconfig docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99 inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::5484:7aff:fefe:9799/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:103571 errors:0 dropped:0 overruns:0 frame:0 TX packets:168898 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5959403 (5.9 MB) TX bytes:250822609 (250.8 MB) eth0 Link encap:Ethernet HWaddr 11:11:11:11:11:11 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:13818 errors:0 dropped:0 overruns:0 frame:0 TX packets:13818 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1315817 (1.3 MB) TX bytes:1315817 (1.3 MB) veth9538 Link encap:Ethernet HWaddr 1e:5d:32:39:ad:c2 inet6 addr: fe80::1c5d:32ff:fe39:adc2/64 Scope:Link UP BROADCAST RUNNING MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:7 errors:0 dropped:1 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:648 (648.0 B) TX bytes:558 (558.0 B) wlan0 Link encap:Ethernet HWaddr 10:10:10:10:10:10 inet addr:192.168.1.106 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::ae72:89ff:fef4:358a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:3740188 errors:0 dropped:0 overruns:0 frame:0 TX packets:2472330 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5267690063 (5.2 GB) TX bytes:246334898 (246.3 MB)
接下来,进行安装debian的镜像,使用docker search来搜索一下关于debian的镜像,
$ sudo docker search debain NAME DESCRIPTION STARS OFFICIAL AUTOMATED bailaohe/java Docker Image with Oracle JDK7 installed o... 0 [OK] rangalo/debian Debain wheezy with some basic tools like w... 0 [OK]
安装rangalo/debian的镜像,使用docker pull命令,
$ sudo docker pull rangalo/debian Pulling repository rangalo/debian ce6dc3910f8d: Download complete 511136ea3c5a: Download complete 2e5f1fce06be: Download complete 63f650c4db34: Download complete 431ffbc97c99: Download complete 52fc6fdb293f: Download complete
查看系统中的docker镜像,使用docker images命令,
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu/wget nginx_v1 51bc7cd125d7 43 minutes ago 633.6 MB ubuntu/wget nginx a4e70c05a75d 57 minutes ago 579.7 MB ubuntu/wget latest 6c95a7fc2fd2 About an hour ago 134.7 MB ubuntu latest 6d4946999d4f 2 weeks ago 188.3 MB ubuntu 12.04 5c97af892079 3 weeks ago 133.4 MB rangalo/debian latest ce6dc3910f8d 12 months ago 124.5 MB
启动刚刚下载的rangalo/debian镜像,使用docker run命令,
$ sudo docker run -i -t rangalo/debian /bin/bash
其中,-i, --interactive
-t, --tty
root@1fbc03b63a70:/# root@1fbc03b63a70:/# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 29: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 02:53:a8:21:96:34 brd ff:ff:ff:ff:ff:ff inet 172.17.0.14/16 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::53:a8ff:fe21:9634/64 scope link valid_lft forever preferred_lft forever
可以看到,该容器的IP地址为172.17.0.14,我们ping一下我们的宿主机,看是否能够通信?
root@1fbc03b63a70:/# ping -c 2 172.17.42.1 PING 172.17.42.1 (172.17.42.1): 48 data bytes 56 bytes from 172.17.42.1: icmp_seq=0 ttl=64 time=0.167 ms 56 bytes from 172.17.42.1: icmp_seq=1 ttl=64 time=0.124 ms --- 172.17.42.1 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max/stddev = 0.124/0.146/0.167/0.000 ms
好了,休息一下吧。
本文出自 “天道酬勤” 博客,请务必保留此出处http://lavenliu.blog.51cto.com/5060944/1666269
原文地址:http://lavenliu.blog.51cto.com/5060944/1666269