Alpine Linux 安装 Docker

Alpine Linux Docker WSL About 3,422 words

包管理器

Alpine Linux包管理器community镜像源中包含了Docker安装包,可直接使用包管理器apk命令安装。

阿里镜像源(/etc/apk/repositories):

https://mirrors.aliyun.com/alpine/latest-stable/main/
https://mirrors.aliyun.com/alpine/latest-stable/community/

安装 Docker

apk add docker

查看安装信息

apk info docker

输出

localhost:~# apk info docker
docker-20.10.16-r0 description:
Pack, ship and run any application as a lightweight container

docker-20.10.16-r0 webpage:
https://www.docker.io/

docker-20.10.16-r0 installed size:
4096 B

podman-docker-4.1.0-r1 description:
Emulate Docker CLI using Podman

podman-docker-4.1.0-r1 webpage:
https://podman.io/

podman-docker-4.1.0-r1 installed size:
16 KiB

查看版本

会列出已安装版本和可升级的版本

localhost:~# apk version docker
Installed:                                Available:
docker-20.10.16-r0                      = 20.10.16-r0

卸载 Docker

apk del docker

配置 Docker

添加开机启动

安装开机启动配置服务

apk add openrc

启动openrc

openrc
mkdir -p /run/openrc/softlevel

设置Docker开机启动

rc-update add docker boot

可能遇到的错:创建/run/openrc/softlevel文件夹即可。

local:~# service docker start
 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel
 * ERROR: sysfs failed to start
 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel
 * ERROR: cgroups failed to start
 * ERROR: cannot start docker as sysfs would not start

添加到组

addgroup <username> docker

示例:添加到root用户组

addgroup root docker

启动 Docker 服务

service docker start

更改 Docker 镜像源

vi /etc/docker/daemon.json

添加内容

{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://ustc-edu-cn.mirror.aliyuncs.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}

重启Docker服务

service docker restart

可能的错误

查看日志

tail -f /var/log/docker.log

错误一

failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.8.8 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
 (exit status 3)

解决方法:/etc/docker/daemon.json中添加:"iptables": false

{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://ustc-edu-cn.mirror.aliyuncs.com",
    "https://docker.mirrors.ustc.edu.cn"
  ],
  "iptables": false
}

错误二

解决方法:以管理员执行命令。(Linux下加sudo执行命令,Windows子系统则以管理员身份打开Shell窗口)

failed to start daemon: Error initializing network controller: Error creating default "bridge" network: permission denied

错误三

Windows子系统运行Docker容器报错

failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: waiting for init preliminary setup: EOF: unknown

下载WSL2https://docs.microsoft.com/zh-cn/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package

设置WSL版本为2。(安装的WSLAlpine

wsl --set-version Alpine 2

参考

Docker-Compose等更多信息可参考:

https://wiki.alpinelinux.org/wiki/Docker

Views: 4,631 · Posted: 2022-07-29

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh