简体   繁体   English

无法将环境变量插入“docker-compose.yaml”中的端口声明

[英]Fail to interpolate the environment variable to ports declaration in "docker-compose.yaml"

docker-compose.yaml docker-compose.yaml

version: "3"

services:

  Database:

    image: postgres
    container_name: Database
    restart: always
    ports:
      - "${DATA_BASE_PORT}:${DATA_BASE_PORT}"

    env_file:
      - 01-Source/Infrastructure/Interactions/ClientAndFrontServer/.env.dataBase.local.public
      - 01-Source/Infrastructure/Interactions/ClientAndFrontServer/.env.dataBase.local.private

    // ...

I made sure that paths to files are correct.我确保文件路径正确。 If to make mistake in these path, the error like如果在这些路径中出错,错误如下

open D:\IntelliJ IDEA\XXX\01-Source\Infrastructure\Interactions\ClientAndFrontServe
r\.env.dataBase.local.publicd: 
The system cannot find the file specified.
`docker-compose` process finished with exit code 14

will occur.会发生。

.env.dataBase.local.public .env.dataBase.local.public

DATA_BASE_HOST=localhost
DATA_BASE_PORT=5432

The error错误

Ttime="2022-10-23T10:51:41+09:00" level=warning msg="The \"v\" variable is not set. Defaulting to a blank st
ring."
1 error(s) decoding:

* error decoding 'Ports': No port specified: :<empty>
`docker-compose` process finished with exit code 15

The env_file directive sets up environment variables inside the container and doesn't affect docker compose. env_file指令在容器设置环境变量,不影响 docker 组合。

To set environment variables you can use in docker compose, you can either name the file .env or you can use the --env-file option on your docker compose commands要设置可在 docker compose 中使用的环境变量,您可以将文件命名为.env ,也可以在 docker compose 命令中使用--env-file选项

To use your database file, you'd do要使用你的数据库文件,你会做

docker-compose --env-file .env.dataBase.local.public up

More info here: https://docs.docker.com/compose/environment-variables/#using-the---env-file--option更多信息在这里: https://docs.docker.com/compose/environment-variables/#using-the---env-file--option

Solution for IntelliJ IDEA IDEs family IntelliJ IDEA IDE 系列的解决方案

In the Docker setup at Run/Debug Configurations , specify the Environment variables file via Modify options :运行/调试配置的 Docker 设置中,通过修改选项指定环境变量文件

在此处输入图像描述

What a pity that GUI available only in local development mode xD遗憾的是 GUI 仅在本地开发模式下可用 xD

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

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