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:
Related
I have created the default WeatherForecast web api project with Docker support.
By default, the dockerfile is using aspnet: 6.0
But I would like to upgrade it to 6.0-jammy-chiseled. This is my dockerfile after I have updated it to 6.0-jammy-chiseled
FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy-chiseled AS build
WORKDIR /src
COPY ["Weather2.csproj", "."]
RUN dotnet restore "./Weather2.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Weather2.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Weather2.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Weather2.dll"]
When I run it, I got an error:
mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled: not found
I try to pull the image manually with docker pull mcr.microsoft.com/dotnet/nightly/aspnet:6.0-jammy-chiseled and it pull without issue.
Based on the Docker file of the official sample app, I think that your Docker file should be revised as
FROM mcr.microsoft.com/dotnet/nightly/aspnet:6.0-jammy-chiseled AS base (add nightly in the image path)
and
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build (remove -chiseled as SDK has no need to be chiseled and Microsoft will not publish chiseled SDK but only chiseled runtime.
I have a docker image with a simple .net core API built in it, it works fine when I push it to heroku, but I am having troubles setting it to run in my localhost to test it locally.
I have this line in my Dockerfile
CMD ASPNETCORE_URLS=http://*:$PORT dotnet test-api.dll
But I can't make it run in "localhost:7050"
I am running the image with the following command
docker run -e PORT=7050 --rm --name api-container test-api
The problem is, it runs fine, but in a strange location, it says Now listening on: http://[::]:80
And I can't access that URL.
Of course, I can just do a simple dotnet run, and test it in the port configured, but I would like to test running a container in my computer, if that makes any sense.
The full Dockerfile is bellow, if it helps
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY . .
RUN dotnet restore
RUN dotnet build --no-restore -c Release -o /app
FROM build AS publish
RUN dotnet publish --no-restore -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
# Padrão de container ASP.NET
# ENTRYPOINT ["dotnet", "CarterAPI.dll"]
# Opção utilizada pelo Heroku
CMD ASPNETCORE_URLS=http://*:$PORT dotnet testeApi.dll
I am trying to scaffold a new dotnet Web Api project inside a docker container using C# but getting an error An error occurred trying to start process 'dotnet.exe' with working directory '/app'. No such file or directory.
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = "new webapi -n WebApi"
}
};
process.Start();
Below is the Dockerfile
#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/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Is there a way to reference the dotnet.exe inside the docker container?
Turns out I was using the runtime as the base image and not the SDK. Here's the updated Dockerfile.
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY . .
RUN dotnet restore "WebApplication1.csproj"
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
WORKDIR /app/publish
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
I am trying to get a default Angular App working inside a Docker container. Here are the steps I have followed:
1) Open Visual Studio 2017 and select: File/New/Project.
2) Select ASP.NET Core Web Application. Click OK.
3) Select .NET Core 2.2 and Angular. I notice that 'Enable Docker Support' is greyed out. Not sure why. Tried the first three steps in Visual Studio 2019 and it is the same. Untick Configure for HTTPS. Click OK.
4) Right click on the project and select Add/Container Orchestration Support. Select the Container Orchestration as Docker Compose and the target OS as Linux.
5) Rebuild the app
When I launch the app I see this:
My Docker File looks like this:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["Web/WebSPA/WebSPA.csproj", "Web/WebSPA/"]
RUN dotnet restore "Web/WebSPA/WebSPA.csproj"
COPY . .
WORKDIR "/src/Web/WebSPA"
RUN dotnet build "WebSPA.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebSPA.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebSPA.dll"]
I saw another question, which suggested changing the DockerFile to something like this:
ARG NODE_IMAGE=node:8.11
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80
FROM ${NODE_IMAGE} as node-build
WORKDIR /web
COPY src/Web/WebSPA .
RUN npm install
RUN npm run build:prod
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY scripts scripts/
COPY src/Web/*/*.csproj /src/csproj-files/
COPY . .
COPY --from=node-build /web/wwwroot /src/src/Web/WebSPA/wwwroot/
WORKDIR /src/src/Web/WebSPA
RUN dotnet publish -c Release -o /app
FROM build AS publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebSPA.dll"]
However, it made no difference.
I create my application and it successfully creates the docker container. When I try and run it
docker run -it --name myapp myapp:latest
I get the following error:
The specified framework 'Microsoft.AspNetCore.All', version '2.1.2' was not found.
...
- The following versions are installed:
2.1.1 at [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
When I log into the container, I can see that, in the /usr/share/dotnet/shared/Microsoft.AspNetCore.All folder, there is one subfolder called 2.1.2.
I can't figure out why it's saying that 2.1.1 is installed and 2.1.2 is not??
The following is my Dockerfile:
FROM microsoft/dotnet:2.1.400-sdk-stretch AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1.400-sdk-stretch AS build
WORKDIR /src
COPY source/application/MyApp/MyApp.csproj source/application/MyApp/
COPY source/application/MyApp.DependentProject/MyApp.DependentProject.csproj source/application/MyApp/
RUN dotnet restore source/application/MyApp/MyApp.csproj
COPY . .
WORKDIR /src/source/application/MyApp
RUN dotnet build MyApp.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish MyApp.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyApp.dll"]
You could try changing:
FROM microsoft/dotnet:2.1.400-sdk-stretch AS base
to
FROM microsoft/dotnet AS base
or
FROM microsoft/dotnet:2.1.2-sdk AS base
See the docker docs and Microsoft docs on dotnet core and docker for further examples