您好,登錄后才能下訂單哦!
這篇文章給大家介紹如何在樹莓派2上創建自己的 Docker 鏡像,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
話說昨天費了半天勁終于在我的樹莓派2上成功安裝了一個 docker.io
(主要是 docker
版本變化, 導致各個教程中描述不一, 而樹莓派上可供 apt-get
安裝的又不是最新版本), 具體過程可參考此文樹莓派2下安裝 docker 記錄, 本以為接下來就能很簡單地按照各種教程所說的 pull
一個鏡像, 運行一個容器, 結果才發現, 樂觀過頭了!
看看我們當前安裝的 docker
的版本, 不太高, 現在官方好像出了 1.8
的.
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
把守護進程跑起來.
開始嘗試下載官方的鏡像, 基本上每次 pull
都會報錯, 國內那些公司提供的貌似也沒一個能正常 pull
下來, 這時看到有家公司專門為樹莓派搞了個內置 docker
的發行版, 是這個Getting started with Docker on your Raspberry Pi, 不過我覺得我的 raspbian
運行得好好的, 而且上面裝滿了各種軟件, 僅僅為了嘗試下 docker
就全部換掉有些不太劃算. 所以這種方案暫時不予考慮.
這時就開始考慮自己創建克用于 docker
的鏡像了, 搜索了半天, 發現基本上有兩種方法, 如下:
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
的版本.
所以還得想辦法從其他地方找系統包, 最直接的就是到各個 Linux
官網去下載, 繼續嘗試.....
在接連失敗之后, 終于等來了勝利的曙光: 帶有 rootfs
的 ArchLinux
不負眾望地成功了!
先取得 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
了
關于如何在樹莓派2上創建自己的 Docker 鏡像就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。