Docker compose - services.vulcain.ports contains an invalid type, it should be a number, or an object

5.5k Views Asked by At

I'm using Symfony and docker, and believe I've made an error setting up those two, that made me ran into this error in docker compose :

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

while running a docker compose command :

dc exec php vendor/bin/simple-phpunit --filter 'App\\Tests\\EntityTests::testName'

I'll precise my folder architecture may be the issue:

I have a folder /project that is the route of the project

In which there is two folders /frontend and /backend, plus this script to launch back and front:

#!/bin/bash

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

/frontend not being relevant for me, I launched my commands from /api fodler

Which himself contain /docker (with the dockerfile) and /api folder and my docker-compose.

My docker-compose comes from api-platform documentation:

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

And the errors:

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

comes from the way I precise the ports in my docker-compose, given they came from the .env file located in the /backend folder and I'm executing my comand one folder lower in the /api folder.

But if I execute the same comand from /backend, I get this message :

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

Anyone has an idea no how to fix it ?

2

There are 2 best solutions below

3
kalou.net On

When you "docker-compose up" is fired, you probably get the following warnings as well:

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

These 6 variables must be set before the "docker-compose up" command.

0
Yusuf On

please try to down your containers with the corresponding --env-file like

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