Falyoun
Falyoun

Reputation: 3966

How to use yaml env file in docker compose

I have the .env file as yaml format, in other words I have development.yaml file which consists of following let's say:

server:
  port: 3000
  apiPrefix: api/v1
  swagger:
    title: Test
    description: test description
    version: 1.0
    api: /docs
database:
  name: test
  autoLoadModels: true
  synchronize: false
  dialect: postgres

and inside docker-compose.yaml

version: '3.8'
services:
  dev:
    env_file:
      - config/development.yaml
    container_name: test_development_api_docker_container
    image: test_development_api_docker_container:1.0.0
    build:
      context: .
      target: testDevelopmentEnv
      dockerfile: ./Dockerfile
    command: npm run start:debug
    ports:
      - ${port}:${port}
    networks:
      - test_network
    volumes:
      - .:/Users/falyoun/dev/ite/test
      - /Users/falyoun/dev/ite/test/node_modules
    restart: unless-stopped

networks:
  test_network:

In the above file I tried:

and all causes issues like

ERROR: Invalid interpolation format for "ports" option in service "dev": "${server.port}:${server.port}"

or

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

Upvotes: 3

Views: 843

Answers (1)

Arlo Guthrie
Arlo Guthrie

Reputation: 1234

Before you try anything, you should switch from:

docker-compose

to:

docker compose 

The docker-compose tool has been deprecated, and is at this point a fairly stale version (1.25.X) as installed by apt install. Instead, you should remove docker-compose from your computer and install docker-compose-plugin (latest version as of today is 2.6.X).

Upvotes: 2

Related Questions