Bocker - 用100行bash實現Docker

jopen 9年前發布 | 16K 次閱讀 Docker

Bocker是一個用100行bash實現Docker。


必備組件

運行bocker需要以下包。

  • btrfs-progs
  • iproute2
  • iptables
  • util-linux >= 2.25.2

由于大部分發行并沒有搭載足夠新的util-linux版本,所以你可能需要從此here外抓取源文件然后自己編譯它。

另外你的系統需要用下面的配置。

  • A btrfs filesystem mounted under/var/bocker
  • A network bridge calledbridge0and an IP of 10.0.0.1/24
  • IP forwarding enabled in/proc/sys/net/ipv4/ip_forward
  • A firewall routing traffic frombridge0to a physical interface.
  • Abase-imagewhich contains the filesystem to seed your container with.

For ease of use a Vagrantfile is included which will build the needed environment.

Even if you meet the above prerequisites you probably still want to run bocker in a virtual machine. Bocker runs as root and among other things needs to make changes to your network interfaces, routing table, and firewall rules. I can make no guarantees that it wont trash your system.

使用示例

$ bocker init base-image/
Created: img_84632

$ bocker images
IMAGE_ID
img_84632

$ bocker run img_84632 uname -sro
Linux 3.10.0-123.20.1.el7.x86_64 GNU/Linux

$ bocker ps
CONTAINER_ID       COMMAND
ps_12277           uname -sro

$ bocker logs ps_12277
Linux 3.10.0-123.20.1.el7.x86_64 GNU/Linux

$ bocker rm ps_12277
Removed: ps_12277

$ bocker run img_84632 which wget
which: no wget in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

$ bocker run img_84632 yum install -y wget
Installing : wget-1.14-10.el7_0.1.x86_64                                  1/1
Verifying  : wget-1.14-10.el7_0.1.x86_64                                  1/1
Installed  : wget.x86_64 0:1.14-10.el7_0.1
Complete!

$ bocker ps
CONTAINER_ID       COMMAND
ps_14099           which wget
ps_43377           yum install -y wget

$bocker commit ps_43377 img_84632
Removed: img_84632
Created: img_84632

$ bocker run img_84632 which wget
/usr/bin/wget

$ bocker rm ps_14099
Removed: ps_14099

$ bocker rm ps_43377
Removed: ps_43377

$ bocker rm ps_95942
Removed: ps_95942

$ bocker rm img_84632
Removed: img_84632

功能: 當前實現的

  • docker build?
  • docker images
  • docker ps
  • docker run
  • docker logs
  • docker commit
  • docker rm/docker rmi
  • Networking

?bocker initprovides a very limited implemetation ofdocker build

功能: 還沒有實現的

  • Port Forwarding
  • Data Volumes
  • Data Volume Containers

項目主頁:http://www.baiduhome.net/lib/view/home/1437555987303

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!