Docker-compose 读取不稳定的参数

Docker-compose 读取不稳定的参数

我正在尝试为应用程序构建一个容器堆栈并使用该.env文件来传递构建过程中要使用的各种参数。

堆栈配置

    Docker version 20.10.14, build a224086d
    Docker Compose version v2.5.1
    Docker Desktop version 4.8.2 (79419)
.
├── docker
│   ├── php
│   ├── caddy
│── Dockerfile
│── Docker-compose.yml
│── .env
└── README.md

内容.env

###> symfony/framework-bundle ###
APP_NAME=app
APP_ENV=dev
APP_SECRET=05425c77d4ec3dc1c301c4547ca4ac89
###< symfony/framework-bundle ###

###> docker-compose param ###
SERVER_NAME=${APP_NAME}.local
PHP_VERSION=7.4
COMPOSER_VERSION=2.2.10
CADDY_VERSION=2
HTTP_PROXY=''
APCU_VERSION=5.1
PCOV_VERSION=1.0
XDEBUG_VERSION=3.1.2

MARIABDB_VERSION=10.6
MARIADB_DATABASE=${APP_NAME}_data
MARIADB_ROOT_PASSWORD=root
MARIADB_USER=user
MARIADB_USER_PASSWORD=user
###< docker-composer param ###

文件Docker-compose.yaml内容:

version: "3.7"
services:
  db:
    container_name: ${APP_NAME:-app}_db
    image: mariadb:${MARIADB_VERSION:-10.6}
    restart: unless-stopped
    ports:
      - "3306:3306"
    volumes:
      - db_socket:/var/run/mysqld/
    environment:
      MARIADB_INITDB_SKIP_TZINFO: true
      TZ: Europe/Paris
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-root}
      MARIADB_DATABASE: ${MARIADB_DATABASE}
      MARIADB_USER: ${MARIADB_USER:-user}
      MARIADB_PASSWORD: ${MARIADB_PASSWORD:-user}

  php:
    container_name: ${APP_NAME:-app}_php
    restart: unless-stopped
    depends_on:
      - db
    build:
      context: .
      target: php_dev
      args:
        PHP_VERSION: ${PHP_VERSION:-7.4}
        COMPOSER_VERSION: ${COMPOSER_VERSION:-2.2.10}
        HTTP_PROXY: ${HTTP_PROXY}
        XDEBUG_VERSION: ${XDEBUG_VERSION:-5.1.2}
    # https://github.com/compose-spec/compose-spec/blob/master/spec.md#healthcheck
    healthcheck:
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s
    volumes:
      - php_socket:/var/run/php
      - ./app:/srv/app/
    environment:
      # Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
      DATABASE_URL: mysql://${MARIA_USER:-symfony}:${MARIA_USER_PASSWORD:-ChangeMe}@db:3306/${MARIA_DB:-app}?unix_socket=/var/run/mysqld/&serverVersion=${MARIA_VERSION:-10.6}
      # See https://docs.docker.com/docker-for-mac/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
      # See https://github.com/docker/for-linux/issues/264
      # The `client_host` below may optionally be replaced with `discover_client_host=yes`
      # Add `start_with_request=yes` to start debug session on each request
      XDEBUG_CONFIG: >-
        client_host=host.docker.internal
      XDEBUG_MODE: debug
      # This should correspond to the server declared in PHPStorm `Preferences | Languages & Frameworks | PHP | Servers`
      # Then PHPStorm will use the corresponding path mappings
      PHP_IDE_CONFIG: serverName=symfony
      #      extra_hosts:
      #        # Ensure that host.docker.internal is correctly defined on Linux
      #        - host.docker.internal: host-gateway
      # Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
      # https://symfony.com/doc/current/mercure.html
      MERCURE_URL: ${CADDY_MERCURE_URL:-http://caddy/.well-known/mercure}
      MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
      MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}


  caddy:
    build:
      context: .
      target: app_caddy
      args:
        CADDY_VERSION: ${CADDY_VERSION:-2}
    depends_on:
      - php
    restart: unless-stopped
    volumes:
      - php_socket:/var/run/php
      - caddy_data:/data
      - caddy_config:/config
    ports:
      # HTTP
      - target: 80
        published: ${HTTP_PORT:-80}
        protocol: tcp
      # HTTPS
      - target: 443
        published: ${HTTPS_PORT:-443}
        protocol: tcp
      # HTTP/3
      - target: 443
        published: ${HTTP3_PORT:-443}
        protocol: udp
    environment:
      SERVER_NAME: ${SERVER_NAME:-localhost, caddy:80}
      MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}
      MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}


volumes:
  php_socket:
  db_socket:
  caddy_data:
  caddy_config:

内容Dockerfile

ARG PHP_VERSION
ARG CADDY_VERSION
ARG COMPOSER_VERSION
ARG HTTP_PROXY
ARG APCU_VERSION
ARG PCOV_VERSION
ARG XDEBUG_VERSION

# Obliger de charger un https://stackoverflow.com/a/65044947/1374947
FROM composer:${COMPOSER_VERSION} AS composer_local
FROM php:${PHP_VERSION}-fpm-alpine AS php
LABEL "maintainer"="DEIL"
LABEL "version"="1.0"
LABEL "description"="Base image for symfony project"

ARG DEBIAN_FRONTEND=noninteractive

RUN apk update; \
    apk upgrade; \
    apk add --no-cache \
        acl \
        bash \
        fcgi \
        file \
        gettext \
        gnu-libiconv \
        nano \
    ;
# install gnu-libiconv and set LD_PRELOAD env to make iconv work fully on Alpine image.
# see https://github.com/docker-library/php/issues/240#issuecomment-763112749
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN set -eux; \
    apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        icu-dev \
        libzip-dev \
        zlib-dev \
        mysql-client \
        ldb-dev \
        libldap \
        openldap-dev \
        openldap-clients \
        freetype-dev \
        libpng-dev \
        jpeg-dev \
        libjpeg-turbo-dev \
    ; \
    \
    docker-php-ext-configure zip; \
       docker-php-ext-configure ldap; \
    docker-php-ext-install -j$(nproc) \
        intl \
        ldap \
        zip \
        pdo_mysql \
        mbstring \
        gd \
    ; \
    pear config-set http_proxy $HTTP_PROXY; \
    pecl install \
    apcu-${APCU_VERSION} \
    ; \
    \
    runDeps="$( \
        scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
            | tr ',' '\n' \
            | sort -u \
            | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
    )"; \
    apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
    \
    apk del .build-deps; \


COPY ./docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck
HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]
# Configuration optimale fournit par PHP-FPM pour le developement
RUN ln -s $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
COPY docker/php/conf.d/symfony.dev.ini $PHP_INI_DIR/conf.d/symfony.ini

COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf

VOLUME /var/run/php

COPY --from=composer_local /usr/bin/composer /usr/bin/composer
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

WORKDIR /srv/app
RUN set -eux; \
    mkdir -p var/cache var/log; \
    ls -halt /srv/app; \
    mkdir -p var/cache var/log; \
    chmod +x bin/console; sync

CMD ["php-fpm"]

# Dockerfile to include xdebug
# https://github.com/dunglas/symfony-docker/blob/main/docs/xdebug.md
FROM php AS php_dev
RUN set -eux; \
    apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
    pecl install xdebug-$XDEBUG_VERSION; \
    docker-php-ext-enable xdebug; \
    apk del .build-deps ; \

FROM php as php_test
# Ajouter la conf pour PCOV - Code Coverage
COPY ./docker/php-test/pcov.ini  /
RUN set -eux; \
    apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
    pecl install pcov-${PCOV_VERSION}; \
    pecl clear-cache; \
    docker-php-ext-enable pcov; \
    cat /pcov.ini >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini; \
    apk del .build-deps;

WORKDIR /srv/app
## Copie des sources dans le conteneur.
## Copier le composer.json et .lock et installer les dépendances pendant le build.
COPY --chown=www-data:www-data . .

FROM caddy:${CADDY_VERSION}-builder-alpine AS caddy_builder
RUN xcaddy build \
    --with github.com/dunglas/mercure \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/dunglas/vulcain \
    --with github.com/dunglas/vulcain/caddy ;

FROM caddy:${CADDY_VERSION} AS app_caddy
WORKDIR /srv/app

COPY --from=dunglas/mercure:v0.11 /srv/public /srv/mercure-assets/
COPY --from=caddy_builder /usr/bin/caddy /usr/bin/caddy
COPY --from=php /srv/app/public public/
COPY ./docker/caddy/Caddyfile /etc/caddy/Caddyfile

我无法构建图像和相关容器;构建返回以下不稳定错误,涉及 caddy 图像或 php 图像中提到的版本的格式:

λ docker-compose build --pull --no-cache
[+] Building 0.2s (6/6) FINISHED
 => [skeleton-ci_caddy internal] load build definition from Dockerfile                                                                                                                                                                                               0.0s 
 => => transferring dockerfile: 32B                                                                                                                                                                                                                                  0.0s 
 => [skeleton-ci_php internal] load build definition from Dockerfile                                                                                                                                                                                                 0.0s 
 => => transferring dockerfile: 32B                                                                                                                                                                                                                                  0.0s 
 => [skeleton-ci_caddy internal] load .dockerignore                                                                                                                                                                                                                  0.0s 
 => => transferring context: 2B                                                                                                                                                                                                                                      0.0s 
 => [skeleton-ci_php internal] load .dockerignore                                                                                                                                                                                                                    0.0s 
 => => transferring context: 2B                                                                                                                                                                                                                                      0.0s 
 => CANCELED [skeleton-ci_caddy internal] load metadata for docker.io/library/caddy:2-builder-alpine                                                                                                                                                                 0.0s 
 => CANCELED [skeleton-ci_caddy internal] load metadata for docker.io/library/caddy:2                                                                                                                                                                                0.0s 
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to parse stage name "php:-fpm-alpine": invalid reference format

我无法找到导致此错误的原因并纠正它。我是否遗漏了什么?

相关内容