Pacman 在 Docker 镜像中不起作用

Nic*_*lla 8 arch-linux docker

我需要运行 Arch Linux 容器,但我无法在其上安装任何东西:

当我尝试跑步时 pacman -Syyu --noconfirm

error: failed to initialize alpm library
(could not find or read directory: /var/lib/pacman/)
Run Code Online (Sandbox Code Playgroud)

按照那个线程

我跑了

pacman-db-upgrade
Run Code Online (Sandbox Code Playgroud)

但这也失败了:

==> ERROR: You must have correct permissions to upgrade the database.
Run Code Online (Sandbox Code Playgroud)

这个容器是一个archlinux:latest基于vanilla的容器docker run -it archlinux

sic*_*des 7

EDIT2:pacman在 Dockerfile 中的任何位置运行之前和之后添加此内容。

# TEMP-FIX for pacman issue
RUN patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst \
    && curl -LO "https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/${patched_glibc}" \
    && bsdtar -C / -xvf "${patched_glibc}" || echo "Everything is fine."
# TEMP-FIX for pacman issue
Run Code Online (Sandbox Code Playgroud)

我在 Dockerfile 中添加了 4 次:https : //github.com/sickcodes/Docker-OSX/pull/159

编辑:有一个非官方补丁可用,我们复制自:https : //github.com/qutebrowser/qutebrowser/commit/478e4de7bd1f26bebdcdc166d5369b2b5142c3e2

# WORKAROUND for glibc 2.33 and old Docker
# See https://github.com/actions/virtual-environments/issues/2658
# Thanks to https://github.com/lxqt/lxqt-panel/pull/1562
RUN patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst && \
    curl -LO "https://repo.archlinuxcn.org/x86_64/$patched_glibc" && \
    bsdtar -C / -xvf "$patched_glibc"
Run Code Online (Sandbox Code Playgroud)

原文:这是一个实时错误,应该在本周修复(据称)。

https://bugs.archlinux.org/index.php?do=details&task_id=69563

该错误是由于 glibc 2.33 向后兼容,但几乎所有其他发行版都不会在 Docker 内部构建 glibc 2.33。

如果您在 Arch 主机上构建它,它将构建。

它与 runc 有关,实际上已经打了补丁,但我们正在等待以下两种结果之一:

  • 所有其他发行版和建筑服务都在迎头赶上(不要屏住呼吸)
  • 或者为了实现这个 util-linux 修复:https ://bugs.archlinux.org/index.php?do=details&task_id =69613

我们在这里遇到了完全相同的问题,阻止了所有 hub.docker.com 构建:

https://github.com/sickcodes/Docker-OSX/issues/144


Sha*_*iri 5

据我了解,这是因为Docker 的权限配置和运行容器。当我们登录操作系统时,看起来好像是root,但实际上我们没有正确的root权限。这是一个简单的尝试:

root[0]docker:~# docker run -it archlinux:latest bash
[root@c565c90fdb7f /]# pacman
error: failed to initialize alpm library
(could not find or read directory: /var/lib/pacman/)
[root@c565c90fdb7f /]# exit
exit
Run Code Online (Sandbox Code Playgroud)

但如果我们在登录容器时给予正确的 root 权限,那就没问题了。

root[0]docker:~# docker run -it --privileged=true archlinux:latest bash
[root@0d95575abec6 /]# dir
bin  boot  dev  etc  home  lib  lib64  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@0d95575abec6 /]# pacman
warning: database file for 'core' does not exist (use '-Sy' to download)
warning: database file for 'extra' does not exist (use '-Sy' to download)
warning: database file for 'community' does not exist (use '-Sy' to download)
error: no operation specified (use -h for help)
[root@0d95575abec6 /]# pacman -Sy
:: Synchronizing package databases...
 core                                                                                                        131.2 KiB  10.7 MiB/s 00:00 [####################################################################################] 100%
 extra                                                                                                      1654.4 KiB   101 MiB/s 00:00 [####################################################################################] 100%
 community                                                                                                     5.4 MiB   270 MiB/s 00:00 [####################################################################################] 100%
[root@0d95575abec6 /]# exit
exit
Run Code Online (Sandbox Code Playgroud)

因此,对于登录,应该使用Arch Linux此选项,而对于, ,似乎我们不需要它。--privileged=trueDebianAlpineUbunut


已测试:

cat /etc/os-release

NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://www.archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
LOGO=archlinux
Run Code Online (Sandbox Code Playgroud)

 pacman -V

 .--.                  Pacman v5.2.2 - libalpm v12.0.2
/ _.-' .-.  .-.  .-.   Copyright (C) 2006-2020 Pacman Development Team
\  '-. '-'  '-'  '-'   Copyright (C) 2002-2006 Judd Vinet
 '--'
                       This program may be freely redistributed under
                       the terms of the GNU General Public License.
Run Code Online (Sandbox Code Playgroud)

和码头工人

docker -v
Docker version 19.03.6, build 369ce74a3c
Run Code Online (Sandbox Code Playgroud)