因內容可能會根據狀況更新, 因此給出原始連接 本文原始連接linux
話說昨天費了半天勁終於在個人樹莓派2上成功安裝了一個 docker.io
(主要是 docker
版本變化, 致使各個教程中描述不一, 而樹莓派上可供 apt-get
安裝的又不是最新版本), 具體過程可參考此文樹莓派2下安裝 docker 記錄, 本覺得接下來就能很簡單地按照各類教程所說的 pull
一個鏡像, 運行一個容器, 結果才發現, 樂觀過頭了!web
看看咱們當前安裝的 docker
的版本, 不過高, 如今官方好像出了 1.8
的.docker
pi@rpi ~/notebooks $ sudo docker version Client version: 1.3.3 Client API version: 1.15 Go version (client): go1.3.2 Git commit (client): d344625 OS/Arch (client): linux/arm Server version: 1.3.3 Server API version: 1.15 Go version (server): go1.3.2 Git commit (server): d344625 pi@rpi ~/notebooks $ sudo docker info Containers: 6 Images: 4 Storage Driver: devicemapper Pool Name: docker-179:2-73614-pool Pool Blocksize: 65.54 kB Data file: /var/lib/docker/devicemapper/devicemapper/data Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata Data Space Used: 1.208 GB Data Space Total: 107.4 GB Metadata Space Used: 1.516 MB Metadata Space Total: 2.147 GB Library Version: 1.02.90 (2014-09-01) Execution Driver: native-0.2 Kernel Version: 4.1.13-v7+ Operating System: Raspbian GNU/Linux 8 (jessie) WARNING: No swap limit support pi@rpi ~/notebooks $
先執行這條命令 sudo docker -d
把守護進程跑起來.json
開始嘗試下載官方的鏡像, 基本上每次 pull
都會報錯, 國內那些公司提供的貌似也沒一個能正常 pull
下來, 這時看到有家公司專門爲樹莓派搞了個內置 docker
的發行版, 是這個Getting started with Docker on your Raspberry Pi, 不過我以爲個人 raspbian
運行得好好的, 並且上面裝滿了各類軟件, 僅僅爲了嘗試下 docker
就所有換掉有些不太划算. 因此這種方案暫時不予考慮.bootstrap
這時就開始考慮本身建立克用於 docker
的鏡像了, 搜索了半天, 發現基本上有兩種方法, 以下:ubuntu
1 用 debootstrap, 不幸的是在個人樹莓派2上執行會返回錯誤
2 本身用 `tar` 命令把當前使用的 `raspbian` 系統打包, 而後用第3種辦法, 試了一半, 發現打出來的包太大, 中途放棄了
3 找一個Linux系統 `ISO`, 使用 `sudo docker import` 命令導入爲 `docker image`
4 找一個Linux系統 `tar` 包(就好像安裝包同樣), 使用 `sudo docker import` 命令導入爲 `docker image`
那麼如今就只有第4種辦法可行了, 有個網站OpenVZ專門提供這種系統包模板, 在這裏下載了幾個系統模板回來導入成 docker image
, 能夠成功導入, 可是沒辦法執行命令, 猜想多是由於樹莓派2須要特別的ARMV7版本, 而這個網站提供的都是 x86
的版本.bash
因此還得想辦法從其餘地方找系統包, 最直接的就是到各個 Linux
官網去下載, 繼續嘗試.....app
在接連失敗以後, 終於等來了勝利的曙光: 帶有 rootfs
的 ArchLinux
不負衆望地成功了!post
先取得 ArchLinux
, 這個版本同時支持樹莓派1代和2代:網站
pi@rpi ~/notebooks $ wget http://212.187.212.74/bt/ab301ea7ea245c12ea9babf5235d75b04890bbd4/data/ArchLinuxARM-2014.10-rpi-rootfs.tar.gz --2015-12-30 17:02:23-- http://212.187.212.74/bt/ab301ea7ea245c12ea9babf5235d75b04890bbd4/data/ArchLinuxARM-2014.10-rpi-rootfs.tar.gz Connecting to 212.187.212.74:80... connected. HTTP request sent, awaiting response... 200 OK Length: 220637379 (210M) [application/x-gzip] Saving to: `ArchLinuxARM-2014.10-rpi-rootfs.tar.gz' 74% [================================================================================> ] 163,600,832 --.-K/s in 55m 51s 2015-12-30 17:58:15 (47.7 KB/s) - Read error at byte 163600832/220637379 (Connection timed out). Retrying. --2015-12-30 17:58:16-- (try: 2) http://212.187.212.74/bt/ab301ea7ea245c12ea9babf5235d75b04890bbd4/data/ArchLinuxARM-2014.10-rpi-rootfs.tar.gz Connecting to 212.187.212.74:80... connected. HTTP request sent, awaiting response... 206 Partial Content Length: 220637379 (210M), 57036547 (54M) remaining [application/x-gzip] Saving to: `ArchLinuxARM-2014.10-rpi-rootfs.tar.gz' 100%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++============================>] 220,637,379 837K/s in 79s 2015-12-30 17:59:36 (703 KB/s) - `ArchLinuxARM-2014.10-rpi-rootfs.tar.gz' saved [220637379/220637379] pi@rpi ~/notebooks $
再生成鏡像, 運行 /bin/bash
命令, 至關於建立容器
pi@rpi ~/notebooks $ cat ArchLinuxARM-2014.10-rpi-rootfs.tar.gz |sudo docker import - archlinux 46b927e18f3bb69337c58ae1e195f34eea7b17d0c71ef5dad63d6cbce102f844 pi@rpi ~/notebooks $ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE archlinux latest 46b927e18f3b 5 minutes ago 445.6 MB raring latest e0168fc30ed0 About an hour ago 0 B alpine 3.3.0 0a0aa665bfa2 2 hours ago 85.02 MB ubuntu 14.04 723d8ba23c53 4 hours ago 204.8 MB pi@rpi ~/notebooks $ sudo docker run -ti archlinux /bin/bash [root@d7e0d53e291c /]# ls bin boot dev etc home lib mnt opt proc root run sbin srv sys tmp usr var [root@d7e0d53e291c /]#
看看後臺的打印信息:
[info] POST /v1.15/containers/create [254b957f] +job create() [254b957f] +job log(create, d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37, archlinux:latest) [254b957f] -job log(create, d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37, archlinux:latest) = OK (0) [254b957f] -job create() = OK (0) [info] POST /v1.15/containers/d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37/attach?stderr=1&stdin=1&stdout=1&stream=1 [254b957f] +job container_inspect(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37) [254b957f] -job container_inspect(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37) = OK (0) [254b957f] +job attach(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37) [info] POST /v1.15/containers/d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37/start [254b957f] +job start(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37) [254b957f] +job allocate_interface(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37) [254b957f] -job allocate_interface(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37) = OK (0) [254b957f] +job log(start, d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37, archlinux:latest) [254b957f] -job log(start, d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37, archlinux:latest) = OK (0) [254b957f] -job start(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37) = OK (0) [info] POST /v1.15/containers/d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37/resize?h=47&w=151 [254b957f] +job resize(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37, 47, 151) [254b957f] -job resize(d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37, 47, 151) = OK (0) [info] GET /v1.15/containers/json?all=1 [254b957f] +job containers() [254b957f] -job containers() = OK (0)
看看系統磁盤佔用狀況:
pi@rpi / $ dfc WARNING: /var/lib/docker/devicemapper was skipped because it cannot be stated : Permission denied FILESYSTEM (=) USED FREE (-) %USED AVAILABLE TOTAL MOUNTED ON /dev/root [=============-------] 64% 10.7G 29.6G / devtmpfs [--------------------] 0% 458.7M 458.7M /dev tmpfs [=-------------------] 0% 92.3M 92.6M /run tmpfs [=-------------------] 0% 5.0M 5.0M /run/lock tmpfs [--------------------] 0% 185.2M 185.2M /run/shm /dev/mmcblk0p1 [========------------] 36% 36.1M 55.9M /boot tmpfs [--------------------] 0% 100.0M 100.0M /tmp cgroup [--------------------] 0% 12.0K 12.0K /sys/fs/cgroup cgmfs [--------------------] 0% 100.0K 100.0K /run/cgmanager/fs tmpfs [--------------------] 0% 92.6M 92.6M /run/user/1000 pi@rpi / $ dfc WARNING: /var/lib/docker/devicemapper was skipped because it cannot be stated : Permission denied FILESYSTEM (=) USED FREE (-) %USED AVAILABLE TOTAL MOUNTED ON /dev/root [============--------] 59% 12.2G 29.6G / devtmpfs [--------------------] 0% 458.7M 458.7M /dev tmpfs [=-------------------] 0% 92.3M 92.6M /run tmpfs [=-------------------] 0% 5.0M 5.0M /run/lock tmpfs [--------------------] 0% 185.2M 185.2M /run/shm /dev/mmcblk0p1 [========------------] 36% 36.1M 55.9M /boot tmpfs [--------------------] 0% 100.0M 100.0M /tmp cgroup [--------------------] 0% 12.0K 12.0K /sys/fs/cgroup cgmfs [--------------------] 0% 100.0K 100.0K /run/cgmanager/fs tmpfs [--------------------] 0% 92.6M 92.6M /run/user/1000 pi@rpi / $ dfc WARNING: /var/lib/docker/devicemapper was skipped because it cannot be stated : Permission denied WARNING: /var/lib/docker/devicemapper/mnt/d7e0d53e291c9d8bf149588313439cedc49bf8c00f9c4095cb6fc5ef6ecd2c37 was skipped because it cannot be stated : Permission denied FILESYSTEM (=) USED FREE (-) %USED AVAILABLE TOTAL MOUNTED ON /dev/root [=============-------] 61% 11.4G 29.6G / devtmpfs [--------------------] 0% 458.7M 458.7M /dev tmpfs [=-------------------] 0% 92.3M 92.6M /run tmpfs [=-------------------] 0% 5.0M 5.0M /run/lock tmpfs [--------------------] 0% 185.2M 185.2M /run/shm /dev/mmcblk0p1 [========------------] 36% 36.1M 55.9M /boot tmpfs [--------------------] 0% 100.0M 100.0M /tmp cgroup [--------------------] 0% 12.0K 12.0K /sys/fs/cgroup cgmfs [--------------------] 0% 100.0K 100.0K /run/cgmanager/fs tmpfs [--------------------] 0% 92.6M 92.6M /run/user/1000 pi@rpi / $
畢竟咱們的鏡像比較大, 後面慢慢瘦個身.
有了 docker容器
, 咱們後續就能夠在樹莓派上試驗另外一種集羣 swarm
了
另外, 以前 docker
官方對樹莓派的支持不太有力, 不過看2015年9月的消息, 感受之後會對樹莓派提供更多支持, 畢竟是個宣傳的噱頭:
https://blog.docker.com/2015/09/update-raspberry-pi-dockercon-challenge/
September 15, 2015
Update: Raspberry Pi DockerCon Challenge
By Adam Herzog - Posted in DockerCon, Guest blog posts - Tagged with dockercon, DockerCon 2015, DockerCon Europe, hackathon, hacks, hypriot, raspberry pi
In the DockerCon closing keynote Dieter Reuter from Hypriot presented a demo running 500 Docker containers on a Raspberry Pi 2 device. Convinced that this number of containers could be at least doubled, Dieter then challenged the Docker community to beat his personal record. As of now, the current record stands at 2334 web servers running in containers on a single Raspberry Pi 2.
You can see the original demo here:
[youtube:」https://youtu.be/MHJmNZSRve0?t=1m48s」]