簡體   English   中英

docker 撰寫 env_file 在我的撰寫文件中不起作用

[英]docker compose env_file not working inside my compose file

我已經嘗試了幾種方法,甚至嘗試准確命名文件但仍然無法正常工作。

docker-compose up --build 

錯誤:

WARNING: The APP_SERVER_PORT variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_PORT variable is not set. Defaulting to a blank string.
ERROR: The Compose file './../docker-compose.yml' is invalid because:
services.app.expose is invalid: should be of the format 'PORT[/PROTOCOL]'
services.server.expose is invalid: should be of the format 'PORT[/PROTOCOL]'
services.app.ports contains an invalid type, it should be a number, or an object
services.server.ports contains an invalid type, it should be a number, or an object
 

我的文件夾結構

server
app
docker.compose.yml
env.development
env.production

Docker 編寫文件

version: '3'
services:
  server: 
    build: ./server
    env_file:
      - ./var.env
    expose:
      - ${APP_SERVER_PORT}
    ports: 
      - ${APP_SERVER_PORT}:${APP_SERVER_PORT}
    command: yarn run dev
  app: 
    expose:
      - ${REACT_APP_PORT}
    build: ./client
    env_file:
      - ./var.env
    ports: 
      - ${REACT_APP_PORT}:${REACT_APP_PORT}
    links: 
      - server
    command: yarn run start

我什至嘗試過

env_file:
  - ./.env.development

我的.env.development 文件

APP_SERVER_PORT=3001
REACT_APP_PORT=3000

env_file僅在正在運行的容器上設置環境變量,而不是在 Compose 文件中插入。

要獲得 compose 文件的插值,您的本地 shell 需要定義這些變量。

REACT_APP_PORT=3000 APP_SERVER_PORT=3001 docker-compose up --build

您可以使用 shell 擴展(如direnv來簡化該過程,否則,運行上述命令的Makefile通常用於便攜性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM