简体   繁体   English

如何在 docker 中使用 yaml env 文件

[英]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:我的 .env 文件为 yaml 格式,换句话说,我有development.yaml文件,其中包括以下内容:

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和内部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:在上面的文件中我试过:

  • ${port} ${端口}

  • ${server.port} ${服务器端口}

and all causes issues like和所有原因的问题,如

ERROR: Invalid interpolation format for "ports" option in service "dev": "${server.port}:${server.port}"错误:服务“dev”中“ports”选项的插值格式无效:“${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错误:Compose 文件“./docker-compose.yaml”无效,因为:services.dev.ports 包含无效类型,它应该是数字或 object

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. docker-compose 工具已被弃用,目前是通过 apt install 安装的相当陈旧的版本 (1.25.X)。 Instead, you should remove docker-compose from your computer and install docker-compose-plugin (latest version as of today is 2.6.X).相反,您应该从计算机中删除 docker-compose 并安装 docker-compose-plugin(截至今天的最新版本是 2.6.X)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM