我在我的env.env文件中有两个变量:

问题描述 投票:0回答:1
services: serviceName: container_name: container_name image: image ports: - target: 5000 published: 5000 environment: - YOLO_VERBOSE=False env_file: - path_to_the_env_file volumes: - datasets:/home/${USER_NAME}/rest_of_the_path - model:/home/${USER_NAME}/rest_of_the_path

,我得到了这个错误:
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "USER_NAME" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "HOME_DIR" variable is not set. Defaulting to a blank string.

我正在使用

Docker Compose version v2.32.4
Docker version 24.0.7, build 24.0.7-0ubuntu2~22.04.1

我不明白为什么它没有得到
HOME_DIR

USER_NAME
。我一直在尝试将其放在Docker-Compose文件中:
environment:
  - YOLO_VERBOSE=False
  - USER_NAME=userName
  - HOME_DIR=home

但结果是相同的。 我试图升级Docker-Compose版本,但没有运气。

	
Compose具有两个阶段的环境可变处理。
环境变量引用
直接出现在撰写文件中(例如,在

volumes:
中的路径内)来自普通的UNIX环境,或来自与撰写文件相同的目录中专门命名
.env

的文件。

env_file:

在容器中设置了该过程的环境,但是它确实会直接影响组合文件中的设置。

如果您可以使用此设置
docker docker-compose environment-variables
1个回答
0
投票
将环境文件定义为

.env 删除

env_file:
块。

this this hip this:您在这里显示的环境变量没有意义。  图像中的文件路径通常在图像构建时间固定。  例如,如果Dockerfile说,例如,
ENV DATA_DIR=/home/appuser/rest_of_the_path

如果您在那里安装持久存储,则必须使用该确切的路径。

作为一般规则,制作容器端路径或端口外部配置是没有意义的。 也就是说,您通常不应该在

volumes:

    ports:
  1. 的右侧具有可变引用。 通常不要求这些值与相应的主机设置或非根管容器用户匹配。
    因此,在实践中,我将完全删除此环境变量参考,并在此处使用固定的容器路径
  2. version: '3.8' services: service_name: volumes: - datasets:/home/appuser/datasets - model:/home/appuser/model # ^^^^^^^ using the specific path in the Dockerfile volumes: datasets: model:
  3. 	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.