开发者提示:使用 Docker 快速测试 MariaDB 安装/升级
对于任何想要测试 MariaDB 最新开发版本是否能够安装/升级的开发者来说,这里有一个快速提示。传统上,开发者似乎会准备很多虚拟机来测试 MariaDB 的安装和升级相关事项。对虚拟机镜像进行快照、保持更新、启动、停止等操作都需要花费大量时间,并且感觉很不方便。
一个快得多的选择是为每次测试使用干净的 Docker 镜像。然而,Docker 镜像通常只运行一个进程,因此无法模拟完整的操作系统,并且缺少像 systemd 交互这样的重要功能。
然而,对于这种情况,得益于 Solita 提供的 ubuntu-systemd 和 centos-systemd 镜像,存在一些特殊的 Docker 镜像。以下是如何启动一个内部运行 systemd 的 Ubuntu 18.04 镜像:
1. 准备 cgroup 权限
docker run --rm --privileged -v /:/host solita/ubuntu-systemd:18.04 setup
2. 启动容器
docker run -d --name systemd --security-opt seccomp=unconfined --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t solita/ubuntu-systemd:18.04
3. 检查日志确认启动正常
docker logs systemd
systemd 237 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid)
Detected virtualization docker.
Detected architecture x86-64.
Welcome to Ubuntu 18.04 LTS!
Set hostname to <8dcf4b869050>.
File /lib/systemd/system/systemd-journald.service:36 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
[ OK ] Started Dispatch Password Requests to Console Directory Watch.
[ OK ] Reached target Swap.
[ OK ] Started Forward Password Requests to Wall Directory Watch.
[ OK ] Reached target Local Encrypted Volumes.
-.slice: Failed to reset devices.list: Operation not permitted
user.slice: Failed to reset devices.list: Operation not permitted
[ OK ] Created slice User and Session Slice.
system.slice: Failed to reset devices.list: Operation not permitted
[ OK ] Created slice System Slice.
[ OK ] Reached target Slices.
[ OK ] Listening on /dev/initctl Compatibility Named Pipe.
system-getty.slice: Failed to reset devices.list: Operation not permitted
[ OK ] Created slice system-getty.slice.
[ OK ] Listening on Journal Socket (/dev/log).
[ OK ] Reached target Remote File Systems.
[ OK ] Reached target Paths.
[ OK ] Listening on Journal Socket.
[ OK ] Reached target Local File Systems (Pre).
[ OK ] Reached target Local File Systems.
systemd-journald.service: Failed to reset devices.list: Operation not permitted
Starting Journal Service...
[ OK ] Started Journal Service.
4. 连接会话并运行你的测试!
docker exec -it systemd bash
root@8dcf4b869050:/#
例如,如果你想使用我们在 Launchpad 上用于测试构建的 PPA(此 PPA 不定期更新,并非每次构建都会更新),你可以运行以下命令:
apt install software-properties-common
add-apt-repository ppa:mysql-ubuntu/mariadb-10.3
apt-get update
apt install mariadb-server
这种方法的优点是速度快。缺点包括例如无法测试 systemd 脚本在重启时的行为。此外,似乎没有太多预构建的镜像可用于测试任何 Linux 发行版的任何版本。
如果你有更多相关的提示,请在下方评论!
这里还有一个提示,对于互联网连接速度慢的人来说可能非常有用
(或者对 apt 仓库更友好)。
使用 apt-cacher-ng 来加速 apt 下载。
1/ 安装 apt-cacher-ng
2/ 配置 apt-cacher-ng 监听 docker 接口
检查 docker 接口 IP
如果需要,添加 iptables 规则
编辑 /etc/apt-cacher-ng/acng.conf
BindAddress: 172.17.0.1
重启 apt-cacher-ng
检查 apt-cacher-ng 是否正在监听
3/ 在你的容器中使用 apt-cacher-ng 缓存
创建文件 ‘/etc/apt/apt.conf.d/00aptproxy’,内容如下:
Acquire::http::Proxy "http://172.17.0.1:3142";
这可以在 dockerfile 中通过以下方式完成:
ADD 00aptproxy /etc/apt/apt.conf.d
此提示也可用于虚拟机 (KVM/QEMU),只需在 ‘/etc/apt-cacher-ng/acng.conf’ 中添加你的 virbr0 IP。
示例
BindAddress: 172.17.0.1 192.168.122.1