【问题标题】:Updating nextcloud docker container on RPI在 RPI 上更新 nextcloud docker 容器
【发布时间】:2021-11-09 23:40:47
【问题描述】:

我在 Raspberry Pi 上的 docker 容器中运行 nextcloud。我已经按照here 的描述设置了自签名证书。这些是我运行 docker-compose 的文件:

Dockerfile:

FROM nextcloud:apache
COPY setssl.sh /usr/local/bin/
RUN /usr/local/bin/setssl.sh mail@mail.com 172.30.0.2

码头工人撰写:

version: '2'

services:
  nextcloud:
    image: nextcloud_ssl
    build: .
    container_name: nextcloud
    restart: always
    user: 1000:1000
    ports:
      - 8443:443
    volumes:
      - /home/pi/nextcloud/ncdata:/var/www/html
      - /home/pi/nextcloud/ssl:/etc/ssl/nextcloud
      - /home/pi/pictures:/var/www/html/data/files/pics
      - ./php.ini:/usr/local/etc/php/conf.d/zzz-custom.ini
    environment:
      - MYSQL_PASSWORD=xxx
      - MYSQL_DATABASE=xxx
      - MYSQL_USER=xxx
      - MYSQL_HOST=xxx
      - MYSQL_PORT=xxx

networks:
  default:
    external:
      name: mariabridge

setssl.sh

# setssl.sh
# USAGE: setssl.sh <email> <domain>

echo 'SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
SSLCompression off
SSLSessionTickets Off' > /etc/apache2/conf-available/ssl-params.conf
echo "<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin $2
                ServerName $1
" > /etc/apache2/sites-available/default-ssl.conf
echo '
                DocumentRoot /var/www/html

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on

                SSLCertificateFile    /etc/ssl/nextcloud/cert.pem
                SSLCertificateKeyFile /etc/ssl/nextcloud/key.pem

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>
        </VirtualHost>
</IfModule>' >> /etc/apache2/sites-available/default-ssl.conf
a2enmod ssl >/dev/null
a2ensite default-ssl >/dev/null
a2enconf ssl-params >/dev/null

根据上面的链接线程,我必须运行这些命令来更新我的容器:

docker-compose build --pull
docker-compose up -d

我之前已经成功使用过这个。现在,我收到以下错误:

docker-compose build --pull
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Building nextcloud
Sending build context to Docker daemon  45.65GB

Step 1/3 : FROM nextcloud:apache
apache: Pulling from library/nextcloud
Digest: sha256:99d94124b2024c9f7f38dc12144a92bc0d68d110bcfd374169ebb7e8df0adf8e
Status: Image is up to date for nextcloud:apache
 ---> 0dd24a9c32e9
Step 2/3 : COPY setssl.sh /usr/local/bin/
 ---> Using cache
 ---> 360b5260b30a
Step 3/3 : RUN /usr/local/bin/setssl.sh mail@mail.com 172.30.0.2
 ---> Running in 4e77f23a45f2
touch: setting times of '/var/lib/apache2/module/enabled_by_admin/socache_shmcb': Operation not permitted
ERROR: Failed to create marker '/var/lib/apache2/module/enabled_by_admin/socache_shmcb'!
ERROR: Could not enable dependency socache_shmcb for ssl, aborting
touch: setting times of '/var/lib/apache2/site/enabled_by_admin/default-ssl': Operation not permitted
ERROR: Failed to create marker '/var/lib/apache2/site/enabled_by_admin/default-ssl'!
touch: setting times of '/var/lib/apache2/conf/enabled_by_admin/ssl-params': Operation not permitted
ERROR: Failed to create marker '/var/lib/apache2/conf/enabled_by_admin/ssl-params'!
The command '/bin/sh -c /usr/local/bin/setssl.sh mail@mail.com 172.30.0.2' returned a non-zero code: 1
ERROR: Service 'nextcloud' failed to build

我也尝试将它作为 sudo 运行(通常作为 pi 运行),但它并没有解决问题。不知道在这里做什么。 nextcloud 论坛不太主动寻求帮助..

【问题讨论】:

    标签: docker nextcloud


    【解决方案1】:
    Step 3/3 : RUN /usr/local/bin/setssl.sh mail@mail.com 172.30.0.2
     ---> Running in 4e77f23a45f2
    touch: setting times of '/var/lib/apache2/module/enabled_by_admin/socache_shmcb': Operation not permitted
    ERROR: Failed to create marker '/var/lib/apache2/module/enabled_by_admin/socache_shmcb'!
    ERROR: Could not enable dependency socache_shmcb for ssl, aborting
    touch: setting times of '/var/lib/apache2/site/enabled_by_admin/default-ssl': Operation not permitted
    ERROR: Failed to create marker '/var/lib/apache2/site/enabled_by_admin/default-ssl'!
    touch: setting times of '/var/lib/apache2/conf/enabled_by_admin/ssl-params': Operation not permitted
    ERROR: Failed to create marker '/var/lib/apache2/conf/enabled_by_admin/ssl-params'!
    The command '/bin/sh -c /usr/local/bin/setssl.sh mail@mail.com 172.30.0.2' returned a non-zero code: 1
    

    如果现在归档的 RUN 步骤可以正常工作,那是因为您的上游 nextcloud:apache 在 dockerfile 中添加了 USER 行,而他们添加的 USER 无权访问 /var/lib/apache2

    解决方案很简单,如果不够优雅。

    1. 找出USER 设置在nextcloud:apache 上游映像中。
    2. 在运行setssl.shCMD 之前添加您自己的USER 命令,将用户设置为有权访问/var/lib/apache2 的用户
    3. 添加另一个 USER 命令以从 nextcloud:apache 切换回用户。

    我也尝试将它作为 sudo 运行(通常作为 pi 运行),但它没有解决问题。

    不,sudo 不会。这一切都发生在 docker 领域,因此使用 sudo 运行 docker build / docker compose 并不会改变这一切。

    让我再和你分享一个想法。我假设您创作了setssl.shsh 的许多特性之一是默认情况下失败的命令通常不会结束脚本,而大多数非 shell 编程语言在语句生成错误后不会继续运行。您应该始终在shebang 行中使用-e 运行shell,运行set -e,或在非bourn-like shell 中的等效项,以确保您的shell 命令在其命令错误时会出错,这适用于这种情况。 (如果你好奇,setssl.sh 返回最后一个运行的 touch 命令的退出代码,但它应该在失败的 first 命令之后失败!)否则你的 docker 构建将成功但是 docker 镜像没有你需要的文件。

    【讨论】:

    • 非常感谢!我已将 -e 添加到 setssl.sh。 TBH 我不知道如何找出用户。我会尝试下一个云论坛,但我怀疑有人会在那里提供帮助。
    猜你喜欢
    • 2020-07-24
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2021-06-05
    • 1970-01-01
    • 2022-01-21
    • 2017-06-30
    相关资源
    最近更新 更多