在 Docker 裡跑 ZeroNet

在「Play: A P2P Distributed Torrent Site That's Impossible to Shut Down」這邊看到 ZeroNet,標語是使用 P2P 分散式站台:

Real-time updated, P2P websites using Bitcoin cryptography and the BitTorrent network

想說丟進 Docker 裡玩看看,測了一下沒什麼問題,只要 port forwarding 打幾個洞就好了。

先開 port 15441 (對外溝通) 與 port 43110 (UI 用),這兩個是預設值:

$ docker run -p 15441:15441 -p 0.0.0.0:43110:43110 -t -i ubuntu:14.04 /bin/bash

這邊的 0.0.0.0 是開放給任何連的到這台主機的人用,也許你應該用 127.0.0.1 或是 192.168.x.x 之類的 IP 會比較保險。

然後進 Docker container 後裝個 Wget 並且把檔案抓下來解開:

# apt-get install wget
# cd /tmp
# wget https://github.com/HelloZeroNet/ZeroBundle/releases/download/0.1.1/ZeroBundle-linux64-v0.1.1.tar.gz

這邊建議去官網上看一下最新的 Linux 版本是什麼再抓下來跑。接著解開後直接執行兩次 (因為第一次會失敗 XDDD):

# tar zxvf ZeroBundle-linux64-v0.1.1.tar.gz
# cd ZeroBundle
# ./ZeroNet.sh --ui_ip 0.0.0.0
# ./ZeroNet.sh --ui_ip 0.0.0.0

然後你應該就可以在瀏覽器裡開 http://127.0.0.1:43110/ 看到東西了,在 TF 的站上也有提供一些好東西的網址,這邊就不提了...

看起來也可以包成 image 來用,網路上應該有人包...

試玩 LXD

LXDCanonical (Ubuntu 的那家公司) 推的 container 系統,在「Super Fast Local Workloads With LXD, ZFS, and Juju」這篇文章裡雖然是提 ZFS + Juju 這兩個東西,但 LXD 的部份還是給了些可以直接拿來用的資訊。

首先先安裝 LXD,我是裝 ppa:ubuntu-lxc/stable 這個版本,裝完 lxd 後就照著先執行:

$ newgrp lxd
$ lxd init

由於沒有裝 zfs,就用 dir 模式跑就好了。網路的部份就先選 no 混過去,反正 NAT 會通... 接著就拉 image 回來:

$ lxd-images import ubuntu trusty amd64 --sync --alias ubuntu-trusty

拉完後就可以跑起來了:

$ lxc launch ubuntu-trust test
$ lxc exec test /bin/bash

直接打 lxc 也可以看到一些說明,用過 Docker 的人應該是沒什麼問題,還蠻簡單的。

Docker 預定將 Official Image 從 Ubuntu 換到 Alpine Linux

在「Docker Official Images are Moving to Alpine Linux」這邊看到的消息,消息引用自 Hacker News 上的討論串:「CoreOS Overview, Part One (deis.com)」,其中 shykes 這樣說:

Disclaimer: I work at Docker.

Incidentay, we have hired Natanael Copa, the awesome creator of Alpine Linux and are in the process of switching the Docker official image library from ubuntu to Alpine. You can help us with pull requests to https://github.com/docker-library if you want :)

所以已經雇用 Alpine 的創辦人,並且開始把 Docker 所使用的 Ubuntu-based image 換成 Alpine-based image,後續應該會有更多消息 (& 更正式的消息) 被放出來...

超小的 Docker Image

Hacker News Daily 上看到「Super small Docker image based on Alpine Linux」這個專案,看了一下是 BusyBox 類的專案,不過套件支援度比起其他 BusyBox 專案多不少。

基於 Alpine Linux 的系統:

Alpine Linux is an independent, non-commercial, general purpose Linux distribution designed for power users who appreciate security, simplicity and resource efficiency.

musl libc 與 BusyBox:

Alpine Linux is built around musl libc and busybox. This makes it smaller and more resource efficient than traditional GNU/Linux distributions. A container requires no more than 8 MB and a minimal installation to disk requires around 130 MB of storage. Not only do you get a fully-fledged Linux environment but a large selection of packages from the repository.

可以拿來玩看看,不過一般狀態下應該還是會拿 UbuntuDebian 的系統來用吧,環境標準多了。(不需要自己花時間找問題)

Bocker:用 bash 與 btrfs 疊出來的 Docker

Bocker 這個專案的標語是「Docker implemented in 100 lines of bash」。

有研究過 Docker 實作的人會了解到,最基本版的 Docker 其實最難的是那層可疊的 Filesystem,其他的主要是拿現成的東西出來包裝。

而 Bocker 就是把 btrfs 拿出來用,解決 Layered Filesystem 的問題。而週邊目前有些東西要自己設定而已,其實完成度不低?

相當打臉 XDDD

用 Docker 測試 Mesos

照著「Deploy a Mesos Cluster with 7 Commands Using Docker」上面的方法做,遇到一些小狀況,解決後總算是搞定了。

文章作者的目的是利用 Docker 在不弄髒環境下讓人很容易上手測試,不需要處理一堆 Java 以及設定檔的問題。讓沒有用過的人可以感受一下 MesosMarathon 的界面與操作。

總共會跑起四個 docker instance,分別是 ZooKeeper、Mesos Master、Marathon、Mesos Slave Container。

我遇到的問題是我在 Ubuntu 上面的 UFW 設為 default deny,造成這四隻程式之間溝通不良,最後是針對 docker0 這個 interface 放行:

# ufw allow in on docker0

有些感覺之後就可以看官網看更進階的功能操作。

Ubuntu Core 與 Snappy Transactional Updates

OSNews 上看到「Announcing Ubuntu Core, with snappy transactional updates」,原文出自 Ubuntu 老大 Mark Shuttleworth 的文章「Announcing Ubuntu Core, with snappy transactional updates!」。

依照官方說明:

Ubuntu Core is a minimal server image with the same libraries as today’s Ubuntu, but applications are provided through a simpler mechanism.

希望提供比較穩定的套件環境,並且讓 app 之間不受干擾執行。系統裡分成 release、framework、app 三種角色,release 就是 Ubuntu Core,而 framework 可以是 Docker,最後的 app 就是自己的應用程式,而 snappy 就是管理這三個的軟體。

Snappy Ubuntu Core 是個 readonly image (裡面大多數的地方都不能寫,只有部份目錄以及用 tmpfs 掛起來的部份可以寫入)。

除了可以在雲端平台上面測試外,還可以用 QEMU 掛起來跑,不過實際測試的時候發現 precise (12.04) 的 QEMU 因為是 1.0 版所以不能跑,要 trusty (14.04) 附的版本才夠新 (2.0 版,需要 1.1+)。

找到 trusty 的機器跑的時候因為是遠端的機器,要多加上 -nographic -curses 的參數:

sudo kvm -m 512 -nographic -curses -redir :8090::80 -redir :8022::22 ubuntu-core-alpha-01.img

然後就可以依照官方文件裡提到的方法連進去了:

ssh -p 8022 ubuntu@localhost

然後就可以照著官方的文件操作一次,我自己沒遇到什麼問題。

看起來是 Ubuntu 自己在推動的一套標準,不知道市場接受度如何 :p

Docker 與 Rocket

兩邊開始喊話了。

CoreOS 的人首先先發表了 Docker 的替代品 Rocket:「CoreOS is building a container runtime, Rocket」。

Docker 的人則發文反擊:「Initial thoughts on the Rocket announcement」。

目前資訊不足,不知道起因是什麼,不過已知 Docker 後面是 dotCloud,而 dotCloud 的記錄不太好。

繼續觀察看看吧。

如何做出好的 Docker Image

Docker 愈來愈紅,而 image 也愈來愈多,於是就有人討論要如何做出好的 Docker image。

在「Building good docker images」這篇文章裡提到了不少現象以及改善的技巧。

首先是 base image 的選用。除非有特別的理由,不然作者建議是基於 debian:wheezy (85MB) 而非 ubuntu:14.04 (195MB)。甚至在某些極端的情況下,你可以選擇 busybox (2MB)。

再來是沒事不要塞 build tools 進去,除非那是之後執行必要的東西。

然後是避免暫存檔的產生,作者舉的例子還蠻容易懂的。這樣是 109MB:

FROM debian:wheezy
RUN apt-get update && apt-get install -y wget
RUN wget http://cachefly.cachefly.net/10mb.test
RUN rm 10mb.test

而這樣只有 99MB,原因是每一個 RUN 都會疊一層上去:

FROM debian:wheezy
RUN apt-get update && apt-get install -y wget
RUN wget http://cachefly.cachefly.net/10mb.test && rm 10mb.test

所以,同樣的道理,要避免暫存檔時,可以考慮這種寫法:

wget -O - http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz | tar zxf -

以及裝完後馬上 clean:

FROM debian:wheezy
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*

後面還有一些技巧,不過前面講的空間問題比較重要。