Alpine linux 安装docker时提示docker(missing)

习惯了用alpine linux来跑老机器,因为轻便高效,只用来跑docker之类的很合适。

最近又淘汰下来一台十几年的老服务器,装个alpine linux用来发挥余热。安装很简单,下载ISO镜像,用工具写入U盘启动,然后输入setup-alipine跟着提示一步步就完成了。

但是来到了安装docker的时候,输入#apk add docker出现如下提示:

localhost:~# apk add docker
ERROR: unsatisfiable constraints:
  docker (missing):
    required by: world[docker]

感觉熟悉又忘记上次怎么搞的了,过了好几年了。上去官网找了一下docker安装指引也没提到这回事。

想了一会好像是这么回事,然后跑去打开更新源的配置文件,又想起来上次怎么弄的了。

localhost:/etc/apk# cat repositories
#/media/sdb/apks
http://dl-cdn.alpinelinux.org/alpine/v3.12/main
#http://dl-cdn.alpinelinux.org/alpine/v3.12/community
#http://dl-cdn.alpinelinux.org/alpine/edge/main
#http://dl-cdn.alpinelinux.org/alpine/edge/community
#http://dl-cdn.alpinelinux.org/alpine/edge/testing

把里面的更新源第二行community前面的#删掉,然后回到命令行更新apk配置,再运行docker安装就好了。

localhost:/etc/apk# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
v3.12.1-15-gcb84081c23 [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]
v3.12.1-14-gd1a8d3ca7e [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]
OK: 12744 distinct packages available

再次运行如下命令即可完成安装。

#apk add docker
(1/13) Installing ca-certificates (20191127-r4)
(2/13) Installing libseccomp (2.4.3-r0)
(3/13) Installing runc (1.0.0_rc10-r1)
(4/13) Installing containerd (1.3.4-r1)
(5/13) Installing libmnl (1.0.4-r0)
(6/13) Installing libnftnl-libs (1.1.6-r0)
(7/13) Installing iptables (1.8.4-r2)
(8/13) Installing iptables-openrc (1.8.4-r2)
(9/13) Installing tini-static (0.19.0-r0)
(10/13) Installing docker-engine (19.03.12-r0)
(11/13) Installing docker-openrc (19.03.12-r0)
(12/13) Installing docker-cli (19.03.12-r0)
(13/13) Installing docker (19.03.12-r0)

然后把docker服务添加到开机启动,然后启动docker服务。

localhost:/etc/apk# rc-update add docker boot
 * service docker added to runlevel boot
localhost:/etc/apk# service docker start
 * Caching service dependencies ...                                                        [ ok ]
 * Mounting cgroup filesystem ...                                                          [ ok ]
 * /var/log/docker.log: creating file
 * /var/log/docker.log: correcting owner
 * Starting Docker Daemon ...  

再安装一个portainer网页管理docker服务,就完成了。

localhost:/etc/apk# docker volume create portainer_data
portainer_data
localhost:/etc/apk# docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/dock
er.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce