php Composer安装在dockerfile中,而不是在entrypoint中

2ul0zpep  于 2023-11-16  发布在  PHP
关注(0)|答案(1)|浏览(104)

对于上下文,我试图用php(fpm),nginx和mysql构建一个symfony应用程序的图像。
我在尝试在dockerfile中而不是在入口点中运行composer install时遇到了一些问题。
当我从容器本身执行时,composer安装工作得很好,但当我从dockerfile尝试时,我有两种类型的错误。
举例来说:

Failed to download symfony/twig-bridge from dist: curl error 60 while downloading https://api.github.com/repos/symfony/twig-bridge/zipball/67a33c71062d7d931fe9a8cb7be79cca986a6c09: SSL certificate problem: self signed certificate in certificate chain

字符串

fatal: unable to access 'https://github.com/symfony/web-link.git/': serve
161.6   r certificate verification failed. CAfile: none CRLfile: none


我用docker compose build --no-cache命令运行所有的东西。我试了我在Google上找到的所有东西,都没有用。

这是我的docker-compose.yml

version: '3.8'

services:
  database:
    image: mysql:${MYSQL_VERSION}
    container_name: ${MYSQL_HOST}
    environment:
      MYSQL_ROOT_USER: ${MYSQL_ROOT_USER}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_VERSION: ${MYSQL_VERSION}
    command: ["--default-authentication-plugin=mysql_native_password"]
    ports:
      - ${MYSQL_PORT}:3306
    networks:
      - symfony_app
    volumes:
      - app_mysql_data:/var/lib/mysql
      - ./docker/mysql/my.cnf:/etc/mysql/my.cnf

  php:
    container_name: app-php
    build:
      context: ./
      dockerfile: ./docker/php/Dockerfile
      target: php_local
      args:
        TIMEZONE: ${TIMEZONE}
        USER_PHP: ${USER_PHP}
        USER_ID: ${USER_ID}
        USER_GROUP_PHP: ${USER_GROUP_PHP}
    volumes:
      - ./:/var/www/symfony:cached
      - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt
      - symfony_app_var:/var/www/symfony/var
      - symfony_app_vendor:/var/www/symfony/vendor
    networks:
      - symfony_app
    depends_on:
      - database

  serveur:
    container_name: app-serveur
    build:
      context: ./docker/nginx
    volumes:
      - ./:/var/www/symfony:cached
      - symfony_app_var:/var/www/symfony/var
      - symfony_app_vendor:/var/www/symfony/vendor
      - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt
    ports:
      - "8700:80"
    networks:
      - symfony_app
    env_file:
      - ./docker/nginx/.env.nginx.local
    depends_on:
      - php

volumes:
  symfony_app_var:
  symfony_app_vendor:
  app_mysql_data:

networks:
  symfony_app:

这是我的php dockerfile

#syntax=docker/dockerfile:1.4

#Image pour build en environnement local
FROM php:8.2-fpm-buster as php_base

ARG TIMEZONE
ARG USER_PHP
ARG USER_ID
ARG USER_GROUP_PHP

ENV APP_ENV=dev
WORKDIR /var/www/symfony

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
COPY --link ./docker/php/php.ini $PHP_INI_DIR/conf.d/docker-php-config.ini

# General installation
RUN apt-get update && apt-get install -y \
    ca-certificates \
    gnupg \
    g++ \
    procps \
    openssl \
    git \
    unzip \
    zlib1g-dev \
    libzip-dev \
    libfreetype6-dev \
    libpng-dev \
    libjpeg-dev \
    libicu-dev  \
    libonig-dev \
    libxslt1-dev \
    acl \
    && echo 'alias sf="php bin/console"' >> ~/.bashrc

RUN docker-php-ext-configure gd --with-jpeg --with-freetype

RUN docker-php-ext-install \
    pdo pdo_mysql zip xsl gd intl opcache exif mbstring

# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
    && printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
    && "date"

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# exec entrypoint
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-app-entrypoint
RUN chmod +x /usr/local/bin/docker-app-entrypoint

#Prepare composer installation
COPY --link composer.* symfony.* ./

# Add a non-root user to run the application
RUN groupadd -g ${USER_ID} ${USER_GROUP_PHP} \
    && useradd -u ${USER_ID} -g ${USER_GROUP_PHP} -s /bin/bash -m -d /home/${USER_PHP} ${USER_PHP}

# Default directories + non root user rights
RUN mkdir -p var/cache var/logs var/sessions \
        # Fixes permissions issues in non-dev mode
    && chown -R ${USER_PHP} . var/cache var/logs var/sessions

ENTRYPOINT ["docker-app-entrypoint"]

CMD ["php-fpm"]

# basic image
FROM php_base as php_local

ENV APP_ENV=dev XDEBUG_MODE=off

USER ${USER_PHP}


我真的需要一些帮助,因为我真的在这个错误上挣扎.而且,我真的不明白证书是如何验证的。

EDIT:我的Dockerfile的最后更新,不工作

#syntax=docker/dockerfile:1.4

FROM php:8.2-fpm-buster as php_base

ARG TIMEZONE
ARG USER_PHP
ARG USER_ID
ARG USER_GROUP_PHP

ENV APP_ENV=dev
WORKDIR /var/www/symfony

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
COPY --link ./docker/php/php.ini $PHP_INI_DIR/conf.d/docker-php-config.ini

RUN apt-get update && apt-get install -y \
    ca-certificates \
    gnupg \
    g++ \
    procps \
    openssl \
    git \
    unzip \
    zlib1g-dev \
    libzip-dev \
    libfreetype6-dev \
    libpng-dev \
    libjpeg-dev \
    libicu-dev  \
    libonig-dev \
    libxslt1-dev \
    acl \
    && echo 'alias sf="php bin/console"' >> ~/.bashrc

RUN docker-php-ext-configure gd --with-jpeg --with-freetype

RUN docker-php-ext-install \
    pdo pdo_mysql zip xsl gd intl opcache exif mbstring

COPY --link ./docker/php/cacert.pem /usr/local/share/ca-certificates/cacert.crt
RUN chmod 644 /usr/local/share/ca-certificates/cacert.crt && update-ca-certificates

# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
    && printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
    && "date"

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# exec entrypoint
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-app-entrypoint
RUN chmod +x /usr/local/bin/docker-app-entrypoint

#Prepare composer installation
COPY --link composer.* symfony.* ./

# Add a non-root user to run the application
RUN groupadd -g ${USER_ID} ${USER_GROUP_PHP} \
    && useradd -u ${USER_ID} -g ${USER_GROUP_PHP} -s /bin/bash -m -d /home/${USER_PHP} ${USER_PHP}

# Default directories + non root user rights
RUN mkdir -p var/cache var/logs var/sessions \
        # Fixes permissions issues in non-dev mode
    && chown -R ${USER_PHP} . var/cache var/logs var/sessions

ENTRYPOINT ["docker-app-entrypoint"]

CMD ["php-fpm"]

#Image pour build en environnement local
FROM php_base as php_local

ENV APP_ENV=dev XDEBUG_MODE=off

RUN composer install --prefer-dist --no-interaction

USER ${USER_PHP}

rsaldnfx

rsaldnfx1#

如果有自签名的证书,这是cUrl的问题。只需在cUrl命令中添加--insecure,告诉它忽略证书并允许未经验证的请求。

相关问题