为了账号安全,请及时绑定邮箱和手机立即绑定

alpine linux 环境中安装 docker

标签:
Linux

alpine 环境中安装 docker

  • alpine linux 是一个基于安全的轻量级 Linux 发行版,基于 musl libc 和 busybox。alpine linux 由于简单安全,非常适合 docker 的 linux 发行版,并且被 docker 官方所推荐用来取代 ubuntu。它不但非常小,仅有 5m 左右,而且经过优化可以在 RAM 中运行
  • 既然这么省资源,那么本文就尝试在虚拟机中安装 alpine,然后安装 docker
  • 官方文档

下载

  • alpinelinuxhttps://www.alpinelinux.org/downloads/,这里选择VIRTUAL,它与标准版相似、瘦下来的内核、针对虚拟系统进行了优化。
  • 下载地址链接
  • 下载得到的文件是alpine-virt-3.9.4-x86_64.iso,大小 35m

VMware 中安装

  • 按道理 VirtualBox 也是一样的,VMware 的新建虚拟机的设置中,操作系统类型选择Linux,版本选择其他Linux 4.x 或更高版本内核 64 位
  • 其他步骤按照提示来就行了,问题不大。新建完后启动虚拟机

设置 alpine

apk 介绍

安装 docker

  • Docker 包位于“社区”存储库中,因此如果 apk 添加失败且具有不可满足的约束,则需要编辑/etc/apk/repositories文件以添加(或取消注释)一行,如:http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
  • 更新索引存储库apk update
  • 开始安装apk add docker
  • 要在引导时启动 Docker 守护程序,请运行:rc-update add docker boot
  • 然后手动启动 Docker 守护程序,运行:service docker start
  • 参考alpinelinux Docker

运行

  • 启动service docker start
  • docker run hello-word
localhost:/etc/docker# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

问题

  • 上面安装完 docker 之后,使用命令docker -v可查看版本,但是容器相关命令出错
localhost:~# docker ps
Cannot connect to the Docker daemon at unix:///var/rundocker.sock. Is   the docker daemon running?
  • 通过命令service docker start也启动 docker,`/var/run/docker.sock 也确实存在。
  • 折腾一番之后,查看日志cat ./var/log/docker.log,得到关键信息Error starting daemon: Devices cgroup isn't mounted
cat ./var/log/docker.log
localhost:/etc/docker# rc-update add docker boot
 * service docker added to runlevel boot
localhost:/etc/docker# service docker start
 * Mounting cgroup filesystem ...
 * Starting docker ...
  • 所以整个问题的根源是cgroup filesystem没有挂载,在执行rc-update add docker boot后在启动就好了

总结

  • 多次总结,使用一款产品,第一件事就是找到文档,文档实在晦涩难懂的情况,那么可能有翻译版或者国内版,毕竟官方的才是最权威的
  • 其次是每个人用起来遇到的环境可能不一样,遇到的问题也就不一样,但所有的解决思路中,查看日志这一条是我觉得始终应该第一考虑的,它很明白告诉你,出错了,出了什么错,可能还有出错的具体位置以及建议解决方案
  • end
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消