Docker compose - services.vulcain.ports包含无效类型,它应该是数字或对象

bxjv4tth  于 2023-02-21  发布在  Docker
关注(0)|答案(2)|浏览(303)

我正在使用Symfonydocker,我相信我在设置这两个时犯了一个错误,这让我在docker compose中遇到了这个错误:
services.vulcain.ports contains an invalid type, it should be a number, or an object
运行Docker编写命令时:
dc exec php vendor/bin/simple-phpunit --filter 'App\\Tests\\EntityTests::testName'
我会精确我的文件夹架构可能是问题:
我有一个文件夹/project,它是项目的路径
其中有两个文件夹/frontend/backend,加上此脚本以启动后端和前端:

#!/bin/bash

docker-compose -f backend/docker-compose.yml up -d ; 
docker-compose -f frontend/docker-compose.yml up -d ;

/frontend与我无关,我从/api fodler启动命令
它本身包含/docker(与dockerfile)和/api文件夹和我的docker-compose。
我的docker-compose来自api平台文档:

version: '3.4'

x-cache-from:
  - &api-cache-from
    cache_from:
      - ${NGINX_IMAGE:-quay.io/api-platform/nginx}
      - ${PHP_IMAGE:-quay.io/api-platform/php}

services:
  php:
    build:
      context: ./api
      target: api_platform_php
      <<: *api-cache-from
    image: ${PHP_IMAGE:-quay.io/api-platform/php}
    healthcheck:
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s
    depends_on:
      - db
      - dev-tls
    volumes:
      - ./api:/srv/api:rw,cached
      - ./api/docker/php/conf.d/api-platform.dev.ini:/usr/local/etc/php/conf.d/api-platform.ini
      - dev-certs:/certs:ro,nocopy
    networks:
      - symfony

  api:
    build:
      context: ./api
      target: api_platform_nginx
      <<: *api-cache-from
    image: ${NGINX_IMAGE:-quay.io/api-platform/nginx}
    depends_on:
      - php
    volumes:
      - ./api/public:/srv/api/public:ro
    networks:
      - symfony

  vulcain:
    image: dunglas/vulcain
    environment:
      - CERT_FILE=/certs/localhost.crt
      - KEY_FILE=/certs/localhost.key
      - UPSTREAM=http://api
    depends_on:
      - api
      - dev-tls
    volumes:
      - dev-certs:/certs:ro,nocopy
    ports:
      - ${VULC_TARGET}:${VULC_PUBLISHED}
    networks:
      - symfony

  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_USER=${POSTGRES_USER}
    volumes:
      - db-data:/var/lib/postgresql/data:rw
    ports:
      - "${DB_TARGET}:${DB_PUBLISHED}"
    networks:
      - symfony

  mercure:
    image: dunglas/mercure
    environment:
      - ALLOW_ANONYMOUS=1
      - CERT_FILE=/certs/localhost.crt
      - CORS_ALLOWED_ORIGINS=*
      - DEMO=1
      - JWT_KEY=${JWT_KEY}
      - KEY_FILE=/certs/localhost.key
      - PUBLISH_ALLOWED_ORIGINS=https://localhost:1337
    depends_on:
      - dev-tls
    volumes:
      - dev-certs:/certs:ro,nocopy
    ports:
      - "${MERC_TARGET}:${MERC_PUBLISHED}"
    networks:
      - symfony

  dev-tls:
    build:
      context: ./docker/dev-tls
    volumes:
      - dev-certs:/certs:rw
    ports:
      - target: 80
        published: 80
        protocol: tcp
    networks:
      - symfony

volumes:
  db-data: {}
  dev-certs: {}

networks:
  symfony:
    driver: bridge

和错误:

ERROR: The Compose file './../docker-compose.yml' is invalid because:
services.db.ports contains an invalid type, it should be a number, or an object
services.mercure.ports contains an invalid type, it should be a number, or an object
services.vulcain.ports contains an invalid type, it should be a number, or an object

来自于我在我的docker-compose中精确端口的方式,因为它们来自位于/backend文件夹中的.env文件,并且我正在执行我的comand文件夹,位于/api文件夹的下面。
但是如果我从/backend执行相同的命令,我会得到以下消息:

Time: 115 ms, Memory: 6.00 MB

No tests executed!

Other deprecation notices (1)

  1x: Since symfony/dotenv 5.1: Passing a boolean to the constructor of "Symfony\Component\Dotenv\Dotenv" is deprecated, use "Dotenv::usePutenv()".
    1x in Dotenv::__construct from Symfony\Component\Dotenv

有人知道怎么修吗?

rdlzhqv9

rdlzhqv91#

当触发“docker-compose up”时,可能还会收到以下警告:

kalou@shinwey:~/t$ docker-compose  up
WARNING: The VULC_TARGET variable is not set. Defaulting to a blank string.
WARNING: The VULC_PUBLISHED variable is not set. Defaulting to a blank string.
WARNING: The DB_TARGET variable is not set. Defaulting to a blank string.
WARNING: The DB_PUBLISHED variable is not set. Defaulting to a blank string.
WARNING: The MERC_TARGET variable is not set. Defaulting to a blank string.
WARNING: The MERC_PUBLISHED variable is not set. Defaulting to a blank string.
ERROR: The Compose file './docker-compose.yml' is invalid because:

services.db.ports contains an invalid type, it should be a number, or an object
services.mercure.ports contains an invalid type, it should be a number, or an object
services.vulcain.ports contains an invalid type, it should be a number, or an object

这6个变量必须在“docker-composite up”命令之前设置。

00jrzges

00jrzges2#

请尝试使用相应的--env-file来关闭容器,例如

docker-compose --env-file .config/.env.prod down

相关问题