无根 docker-compose 无法构建时间刻度图像

问题描述

我已经在 ubuntu 主机上安装了 docker rootless。我有一个用于构建 timescaledb 的 Dockerfile,其中最重要的部分如下所示:

# Install the tools we need for installation
RUN  apt-get update && apt-get -y install gnupg2 lsb-release wget
# Add Postgres and Timescale package repository
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -c -s)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN sh -c "echo 'deb https://packagecloud.io/timescale/timescaledb/debian/ `lsb_release -c -s` main' > /etc/apt/sources.list.d/timescaledb.list"
RUN wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add -
# Install Timescale
RUN apt-get update && apt-get -y install timescaledb-2-postgresql-12=2.0.0-zz~debian10

对应的 docker-compose 文件如下所示:

  timescale:
    tty: true
    volumes:
      - timescale-volume:/var/lib/postgresql/data:rw
    build:
      context: ./timescale
      dockerfile: Dockerfile
    command:
      - /bin/bash
    depends_on:
      - cert-mounter

当我使用 sudo 运行 docker-compose up 时,它工作正常,映像已构建且容器正在运行。如果我无根地执行它,我会收到以下错误:

dpkg: error processing package postgresql-12 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of timescaledb-2-postgresql-12:
 timescaledb-2-postgresql-12 depends on postgresql-12; however:
  Package postgresql-12 is not configured yet.

dpkg: error processing package timescaledb-2-postgresql-12 (--configure):
 dependency problems - leaving unconfigured
Setting up exim4-daemon-light (4.92-8+deb10u5) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set,so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Initializing GnuTLS DH parameter file
Setting up libmailutils5:amd64 (1:3.5-4) ...
Setting up mailutils (1:3.5-4) ...
update-alternatives: using /usr/bin/frm.mailutils to provide /usr/bin/frm (frm) in auto mode
update-alternatives: using /usr/bin/from.mailutils to provide /usr/bin/from (from) in auto mode
update-alternatives: using /usr/bin/messages.mailutils to provide /usr/bin/messages (messages) in auto mode
update-alternatives: using /usr/bin/movemail.mailutils to provide /usr/bin/movemail (movemail) in auto mode
update-alternatives: using /usr/bin/readmsg.mailutils to provide /usr/bin/readmsg (readmsg) in auto mode
update-alternatives: using /usr/bin/dotlock.mailutils to provide /usr/bin/dotlock (dotlock) in auto mode
update-alternatives: using /usr/bin/mail.mailutils to provide /usr/bin/mailx (mailx) in auto mode
dpkg: dependency problems prevent configuration of timescaledb-2-loader-postgresql-12:
 timescaledb-2-loader-postgresql-12 depends on postgresql-12; however:
  Package postgresql-12 is not configured yet.

dpkg: error processing package timescaledb-2-loader-postgresql-12 (--configure):
 dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.28-10) ...
Processing triggers for mime-support (3.62) ...
Errors were encountered while processing:
 postgresql-common
 postgresql-12
 timescaledb-2-postgresql-12
 timescaledb-2-loader-postgresql-12
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt-get update && apt-get -y install timescaledb-2-postgresql-12=2.0.0-zz~debian10' returned a non-zero code: 100
ERROR: Service 'timescale' failed to build

可能是什么问题?其他容器以某种方式构建并无根运行,没有问题......

解决方法

所以我设法让它工作。在我的 fmi2SetContinuousStates 中,我还设置了用户的 Dockerfile,因为我共享一些卷并希望用户的 UID 在容器之间保持一致。因此,在我的 uid 之上,我有以下内容:

Dockerfile

用较低的值替换 uid 解决了问题

RUN useradd --uid 80000 postgres

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...