简体   繁体   English

Dotnet Core Docker 环境变量

[英]Dotnet Core Docker Environment Variables

I ran into some problems with dotnet core 3.1 and the visual Studio generated Dockerfile.我在使用 dotnet core 3.1 和 Visual Studio 生成的 Dockerfile 时遇到了一些问题。

I try to put a password in the environment variables of docker via the Dockerfile but when I get read the varibale with Environment.GetEnvironmentVariable("HETZNER_PASSWORD") the variable is null.我尝试通过 Dockerfile 在 docker 的环境变量中输入密码,但是当我使用Environment.GetEnvironmentVariable("HETZNER_PASSWORD")读取变量时,该变量为空。

I found someone who suggested it the way I tried here我发现有人按照我在这里尝试的方式提出了建议

My Dockerfile looks like this:我的 Dockerfile 看起来像这样:

WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["HetznerStorageboxStat/HetznerStorageboxStat.csproj", "HetznerStorageboxStat/"]
RUN dotnet restore "HetznerStorageboxStat/HetznerStorageboxStat.csproj"
COPY . .
WORKDIR "/src/HetznerStorageboxStat"
RUN dotnet build "HetznerStorageboxStat.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "HetznerStorageboxStat.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV HETZNER_USERNAME=USERNAME
ENV HETZNER_PASSWORD=PASSWORD
ENV INFLUX_URL=http://10.20.10.1:8086/write?db=hetzner
ENTRYPOINT ["dotnet", "HetznerStorageboxStat.dll"]

What am I doing wrong?我究竟做错了什么? All the other tutorials are years old or use ASP.Net所有其他教程都是多年的或使用 ASP.Net

Thanks in advance提前致谢

You can set the environment variable for your service in the docker-compose.override.yml file under environment:您可以在环境下的 docker-compose.override.yml 文件中为您的服务设置环境变量:

在此处输入图片说明

在此处输入图片说明

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

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