這篇文章給大家介紹如何在樹莓派2上創(chuàng)建自己的 Docker 鏡像,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
創(chuàng)新互聯(lián)建站自2013年創(chuàng)立以來,先為永川等服務(wù)建站,永川等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為永川企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
話說昨天費(fèi)了半天勁終于在我的樹莓派2上成功安裝了一個(gè) docker.io
(主要是 docker
版本變化, 導(dǎo)致各個(gè)教程中描述不一, 而樹莓派上可供 apt-get
安裝的又不是最新版本), 具體過程可參考此文樹莓派2下安裝 docker 記錄, 本以為接下來就能很簡單地按照各種教程所說的 pull
一個(gè)鏡像, 運(yùn)行一個(gè)容器, 結(jié)果才發(fā)現(xiàn), 樂觀過頭了!
看看我們當(dāng)前安裝的 docker
的版本, 不太高, 現(xiàn)在官方好像出了 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 $
先執(zhí)行這條命令 sudo docker -d
把守護(hù)進(jìn)程跑起來.
開始嘗試下載官方的鏡像, 基本上每次 pull
都會報(bào)錯(cuò), 國內(nèi)那些公司提供的貌似也沒一個(gè)能正常 pull
下來, 這時(shí)看到有家公司專門為樹莓派搞了個(gè)內(nèi)置 docker
的發(fā)行版, 是這個(gè)Getting started with Docker on your Raspberry Pi, 不過我覺得我的 raspbian
運(yùn)行得好好的, 而且上面裝滿了各種軟件, 僅僅為了嘗試下 docker
就全部換掉有些不太劃算. 所以這種方案暫時(shí)不予考慮.
這時(shí)就開始考慮自己創(chuàng)建克用于 docker
的鏡像了, 搜索了半天, 發(fā)現(xiàn)基本上有兩種方法, 如下:
1 用 debootstrap, 不幸的是在我的樹莓派2上執(zhí)行會返回錯(cuò)誤
2 自己用 `tar` 命令把當(dāng)前使用的 `raspbian` 系統(tǒng)打包, 然后用第3種辦法, 試了一半, 發(fā)現(xiàn)打出來的包太大, 中途放棄了
3 找一個(gè)Linux系統(tǒng) `ISO`, 使用 `sudo docker import` 命令導(dǎo)入為 `docker image`
4 找一個(gè)Linux系統(tǒng) `tar` 包(就好像安裝包一樣), 使用 `sudo docker import` 命令導(dǎo)入為 `docker image`
那么現(xiàn)在就只有第4種辦法可行了, 有個(gè)網(wǎng)站OpenVZ專門提供這種系統(tǒng)包模板, 在這里下載了幾個(gè)系統(tǒng)模板回來導(dǎo)入成 docker image
, 可以成功導(dǎo)入, 但是沒辦法執(zhí)行命令, 猜測可能是因?yàn)闃漭?需要特別的ARMV7版本, 而這個(gè)網(wǎng)站提供的都是 x86
的版本.
所以還得想辦法從其他地方找系統(tǒng)包, 最直接的就是到各個(gè) Linux
官網(wǎng)去下載, 繼續(xù)嘗試.....
在接連失敗之后, 終于等來了勝利的曙光: 帶有 rootfs
的 ArchLinux
不負(fù)眾望地成功了!
先取得 ArchLinux
, 這個(gè)版本同時(shí)支持樹莓派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 $
再生成鏡像, 運(yùn)行 /bin/bash
命令, 相當(dāng)于創(chuàng)建容器
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)
看看系統(tǒng)磁盤占用情況:
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 / $
畢竟我們的鏡像比較大, 后面慢慢瘦個(gè)身.
有了 docker容器
, 我們后續(xù)就可以在樹莓派上試驗(yàn)另一種集群 swarm
了
關(guān)于如何在樹莓派2上創(chuàng)建自己的 Docker 鏡像就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。