I created a new API with VS-2019 and added docker support. On create this builds a new Docker Image & Container and runs it.
When I try to open the container through the Browser it doesn't work, which is expected since the container is attached to VS and that's not running. When I run the project in VS the container works fine.
My question is how do I publish/finalize that container and application. My goal is to be able to access the Container without the need to run Visual Studio.
When I run the docker ps command it does show that the ports are bound, even when VS is not running.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82123f6d26ec mareldockerfoodchain:dev "C:\\remote_debugger\\…" 38 minutes ago Up 36 minutes 0.0.0.0:13102->80/tcp, 0.0.0.0:13101->443/tcp, 0.0.0.0:13100->900/tcp Marel.Docker.Foodchain
Below is my Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 900
ENV APSNETCORE_URLS=https://*:900
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Marel.Docker.Foodchain/Marel.Docker.Foodchain.csproj", "Marel.Docker.Foodchain/"]
RUN dotnet restore "Marel.Docker.Foodchain/Marel.Docker.Foodchain.csproj"
COPY . .
WORKDIR "/src/Marel.Docker.Foodchain"
RUN dotnet build "Marel.Docker.Foodchain.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Marel.Docker.Foodchain.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Marel.Docker.Foodchain.dll"]
Related
I have minimal experience with Docker so if I'm missing something please guide me :)
I've just created a new ASP.Net core app and I checked "Enable Docker support" (I need it, I thought I'd add it later, but I had chosen to add it since the beginning so it would be easier)
The project is now created.
I run the container, press on each of those host ports
and it doesn't connect.
I expected it to work out of the box (without me doing any settings). Am I wrong to expect that?
Is there any settings that I need to have in order to work?
Thanks.
//Edit: if I click on those buttons, it opens up a browser tab with localhost:49158 respectively localhost:49157
My 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:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["best-mediere.csproj", "."]
RUN dotnet restore "./best-mediere.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "best-mediere.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "best-mediere.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "best-mediere.dll"]
Command that VS uses when I press CTRL+F5
docker exec -i -e ASPNETCORE_HTTPS_PORT="49159" -w "/app" bceedb5aab26c8f206363e58dff9ffaba7b2bb8b70a02255482be4a7522ccbd7 sh -c ""dotnet" --additionalProbingPath /root/.nuget/fallbackpackages4 --additionalProbingPath /root/.nuget/fallbackpackages --additionalProbingPath /root/.nu
I am new to docker and wish to set TZ=Australia/NSW to the official dotnet core docker image
I tried adding to ENV TZ=Australia/NSW on line 5, but it didn't work.
Please help.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV TZ=Australia/NSW
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Application.WebAPI/Application.WebAPI.csproj", "Application.WebAPI/"]
RUN dotnet restore "Application.WebAPI/Application.WebAPI.csproj"
COPY . .
WORKDIR "/src/Application.WebAPI"
RUN dotnet build "Application.WebAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Application.WebAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Application.WebAPI.dll"]
The OS version for the aspnet image is Debian GNU/Linux 10
I ran two commands inside the docker container
ln -sf /usr/share/zoneinfo/posix/Australia/NSW /etc/localtime
date
And got the below output:
You could add this to your Dockerfile as part of the Docker build instruction
Run ln -sf /usr/share/zoneinfo/posix/Australia/NSW /etc/localtime
I'm having a lot of issues using docker for a C# application.
Here's the first issue I have: I need to run an image in a docker container running on port 8080. I have tried everything inside Visual Studio 2019 but I can't find a way to make it run on port 8080. Basically when I click on the play button it ignores the entry EXPOSE 8080/tcp of dockerfile and runs the image in a container on a random port.
I have tried running the immage from the command line by using "docker run -d -p 8080:80 aspnetapp" where 'aspnetapp' is the name of the image. Everything seems fine and and in Docker Desktop I can see it was trying to run on port 8080 but the container exits with error code 0.
When I run from Visual Studio everything works fine but I can't change to port 8080.
Here is my dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 8080/tcp
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["ProductDirectory.csproj", "."]
RUN dotnet restore "./ProductDirectory.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "ProductDirectory.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ProductDirectory.csproj" -c Release -o /app/publish
EXPOSE 8080/tcp
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProductDirectory.dll"]
It's a good idea to use multiple stage inside your Dockerfile.
but you should be careful about that because Docker take only the latest part of your dockerfile , in your case it's take only this part :
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProductDirectory.dll"]
where you didn't define the port for your application .
to resolve this issue just add EXPOSE port and specify your port for this section, like that:
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
EXPOSE 8080
ENTRYPOINT ["dotnet", "ProductDirectory.dll"]
And I hope that can help you to fix your issue.
I'm using a Docker Compose file to run two Docker Containers One an Image I already published and one a build. I can not see the image when I go to the configured location.
Docker Compose
version: '3.4'
services:
twslogging:
image: ${DOCKER_REGISTRY-}twslogging
build:
context: .
dockerfile: twsLogging\Dockerfile
ports:
- '8000:8000'
twsUsers:
image: tbennet/twsusers
ports:
- '7000:7000'
DockerFile Loggin (One Built-in Docker compose Up)
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 8000
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1803 AS build
WORKDIR /src
COPY ["twsLogging/twsLogging.csproj", "twsLogging/"]
RUN dotnet restore "twsLogging/twsLogging.csproj"
COPY . .
WORKDIR "/src/twsLogging"
RUN dotnet build "twsLogging.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "twsLogging.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "twsLogging.dll"]
DockerFile (Users Docker file that is published)
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 7000
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1803 AS build
WORKDIR /src
COPY twsUsers/nuget.config ./
COPY ["twsUsers/twsUsers.csproj", "twsUsers/"]
COPY ["twsDatabase/twsDatabase.csproj", "twsDatabase/"]
COPY . .
RUN dotnet restore "twsUsers/twsUsers.csproj" --configfile ./nuget.config
WORKDIR "/src/twsUsers"
RUN dotnet build "twsUsers.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "twsUsers.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "twsUsers.dll"]
PostMan
enter image description here
Ok, I found the answer thanks for the comments they helped me look in the right spot. So For .net Core, this is what you do. on your port the port localhost number then 80 so I changed my port to 7000:80 and ran the compose and it came up. I found the answer looking here https://github.com/dotnet/dotnet-docker/blob/master/samples/run-aspnetcore-https-development.md
What I'm trying to achieve is for the output of ILogger.LogError (and other ILogger methods) to appear in the logs for my Docker container, but to take ILogger out of the equation for now, I've just created a vanilla out-of-the-box Web App API project using the standard template in Visual Studio 2019, seleding .NET Core 2.2 and ticking the box to enable Docker support. Then I added Console.WriteLine("test") in a couple of places that I know for certain will be hit when the application loads (and when a page is loaded). I'm seeing nothing in the container logs in Kitematic, and nothing when I run docker logs.
I'm fairly inexperienced with both Docker and Unix, but as I understood it, Console.WriteLine is supposed to send it's output to stdout which in turn is supposed to be written directly to Docker's logs automatically. Is there some simple trick to get it to behave that way?
Docker file: (unmodified from template default)
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch 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
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]