php 如果docker应该有权限,为什么我在尝试安装imagick时会收到权限错误?

zazmityj  于 2023-04-10  发布在  PHP
关注(0)|答案(1)|浏览(157)

我一直没能解决这个问题,这是因为imagick需要依赖python3.9minimal。我试图做的是用apache为laravel 9项目构建一个php容器。但最后一次运行显然是因为权限问题失败了。我已经通过bash进入了容器,但我不能解决它,我已经改变了权限,我试着用sudo运行runers,但是最后一次运行总是引起冲突。有人知道如何修复这个错误吗?
这是上次运行失败

RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends \
    && pecl install imagick \
    && docker-php-ext-enable imagick

这是我的Dockerfile

FROM php:8.2-apache

# PDO PostgreSQL e MySQL
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get update && apt-get install -y libpq-dev \
    && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql pdo_mysql mysqli
RUN apt-get update \
    && apt-get install -y sendmail libpng-dev \
    && apt-get install -y libzip-dev \
    && apt-get install -y zlib1g-dev \
    && apt-get install -y libonig-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install zip
RUN apt-get update \
  && apt-get install -y zlib1g-dev libzip-dev wget gnupg \
  && docker-php-ext-install zip opcache

# Composer install
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
ENV COMPOSER_ALLOW_SUPERUSER 1

RUN a2enmod rewrite

# here docker load but the page display an err-server
# Enable mod_rewrite for images with apache
#RUN if command -v a2enmod >/dev/null 2>&1; then        a2enmod rewrite headers  ;

ENV APACHE_DOCUMENT_ROOT=/var/www/html/public/
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

RUN apt-get install -y libicu-dev
RUN apt-get update && apt-get install -y libjpeg-dev
RUN apt-get update && apt-get install -y libfreetype6-dev

# Configurar extensiones de PHP necesarias
RUN docker-php-ext-install \
    bcmath \
    intl \
    exif \
    pcntl \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j "$(nproc)" gd
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends \
    && pecl install imagick \
    && docker-php-ext-enable imagick

这是Bash中的错误

Setting up python3.9-minimal (3.9.2-1) ...
Traceback (most recent call last):
  File "/usr/lib/python3.9/py_compile.py", line 215, in <module>
    sys.exit(main())
  File "/usr/lib/python3.9/py_compile.py", line 207, in main
    compile(filename, doraise=True)
  File "/usr/lib/python3.9/py_compile.py", line 172, in compile
    importlib._bootstrap_external._write_atomic(cfile, bytecode, mode)
  File "<frozen importlib._bootstrap_external>", line 126, in _write_atomic
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.9/__pycache__/__future__.cpython-39.pyc.140481138631600'
dpkg: error processing package python3.9-minimal (--configure):
 installed python3.9-minimal package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of python3.9:
 python3.9 depends on python3.9-minimal (= 3.9.2-1); however:
  Package python3.9-minimal is not configured yet.

dpkg: error processing package python3.9 (--configure):
 dependency problems - leaving unconfigured
Setting up libpython3.9-stdlib:amd64 (3.9.2-1) ...
Processing triggers for mailcap (3.69) ...
Processing triggers for libc-bin (2.31-13+deb11u5) ...
Errors were encountered while processing:
 python3.9-minimal
 python3.9
E: Sub-process /usr/bin/dpkg returned an error code (1)

这是docker-compose.yaml

version: "3.9"

services:
    php:
        build:
            context: ./php # Indica onde está o arquivo Dockerfile
            dockerfile: Dockerfile
        container_name: php8.2 # Apelido para o container
        volumes:
            - ./src:/var/www/html/ # Irá copiar o conteúdo da pasta src para o container
        ports: # Mapear as portas para ficarem visiveis na máquina host
            - "80:80"
            - "443:443"
        links: # Criar conexão com o container do banco de dados
            - mysql
    mysql:
        image: mysql
        container_name: mysql-coexa
        restart: always
        ports: 
            - "3306:3306"
        command: --default-authentication-plugin=mysql_native_password
        environment:
            MYSQL_DATABASE: test
            MYSQL_PASSWORD: test
            MYSQL_ROOT_PASSWORD: test 
        volumes:
            - ./dump:/docker-entrypoint-initdb.d
            - ./conf:/etc/mysql/conf.d
            - persistent:/var/lib/mysql
        networks:
            - default
volumes:
  persistent:
pes8fvy9

pes8fvy91#

发现于https://forums.docker.com/t/bug-on-apt-install-permission-denied/100196/9
你是用Snap安装Docker的吗?
显然有一个涉及Docker、Snap和Overlay2的问题,这可能导致在dockerfile中安装Python时出现此权限问题。
解决方案是安装Docker而不使用Snap,或者修改Snap的Docker安装以不使用Overlay2。

edit /var/snap/docker/current/config/daemon.json and replace
“overlay2” with “vfs” for the storage-driver
run sudo snap restart docker

相关问题