简体   繁体   中英

Dotnet Core Docker Environment Variables

I ran into some problems with dotnet core 3.1 and the visual Studio generated 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.

I found someone who suggested it the way I tried here

My Dockerfile looks like this:

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

Thanks in advance

You can set the environment variable for your service in the docker-compose.override.yml file under environment:

在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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