如何在树莓派2上创建自己的Docker镜像
这篇文章给大家介绍如何在树莓派2上创建自己的 Docker 镜像,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
创新互联建站自2013年创立以来,先为永川等服务建站,永川等地企业,进行企业商务咨询服务。为永川企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
在树莓派2[raspbian系统]上创建自己的 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 镜像就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
本文名称:如何在树莓派2上创建自己的Docker镜像
文章路径:http://azwzsj.com/article/gocodh.html