Running docker-compose in Visual Studio doesn’t show env variables

  .net-core, c#, docker, visual-studio

I have a service, Review.Api which has a ConnectionString environment variable in the Dockerfile like so:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src

COPY Review.Api/Review.Api.csproj Review.Api/
COPY Review.Data/Review.Data.csproj Review.Data/
COPY Review.Service/Review.Service.csproj Review.Service/
RUN dotnet restore Review.Api/Review.Api.csproj
COPY . .
WORKDIR /src/Review.Api
RUN dotnet build Review.Api.csproj -c Release -o /app/build

FROM build AS publish
RUN dotnet publish Review.Api.csproj -c Release -o /app/publish

FROM base AS final
WORKDIR /app

ENV ConnectionStrings__Review="Data Source=db,1433;Initial Catalog=Review;uid=sa;pwd=TesT111t!;Integrated Security=false;MultipleActiveResultSets=True"

COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "Review.Api.dll"]

When I run the CLI command docker-compose up --build this adds the environment variable on the service in the container.

However when I debug and run docker-compose through Visual Studio I don’t get this environment and I can’t get my head around why?

Source: Docker Questions

LEAVE A COMMENT