Unable to run localhost after completed docker run - docker

I have successfully run "docker run". How do I browse my web app?
I have tried localhost:8000 and localhost:81 but no success.
Updated with docker ps -a
My dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["WebApplication4/WebApplication4.csproj", "WebApplication4/"]
RUN dotnet restore "WebApplication4/WebApplication4.csproj"
COPY . .
WORKDIR "/src/WebApplication4"
RUN dotnet build "WebApplication4.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebApplication4.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication4.dll"]

You are able to access localhost:52010 since the container that exposed the port 52010 is currently running, however the other containers have all exited. This is probably due to the fact that container ea7 was run with the persistent tail -f /dev/null command, while the other containers were run with the non-persistent bash command.
The reason for this could be that the image you are trying to run does not have any command that persists and as soon as the container is created all running tasks in it are completed and the container exits.
Please make sure webapplication4:dev has a persistent command in it to keep the container from exiting.
Hope this helps !

Related

Docker running dotnet command under Windows and bash under Linux

I have a pretty simple Dockerfile that builds an API image.
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:2.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
WORKDIR /src
COPY ["MyApp.Api/MyApp.Api.csproj", "MyApp.Api/"]
COPY ["MyApp.Common/MyApp.Common.csproj", "MyApp.Common/"]
COPY ["MyApp.Service/MyApp.Service.csproj", "MyApp.Service/"]
COPY ["MyApp.Repository/MyApp.Repository.csproj", "MyApp.Repository/"]
COPY ["MyApp.Data/MyApp.Data.csproj", "MyApp.Data/"]
COPY ["MyApp.Model/MyApp.Model.csproj", "MyApp.Model/"]
COPY ["MyApp.DTO/MyApp.DTO.csproj", "MyApp.DTO/"]
RUN dotnet restore "MyApp.Api/MyApp.Api.csproj"
COPY . .
WORKDIR "/src/MyApp.Api"
RUN dotnet build "MyApp.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.Api.dll"]
Building that way : docker build -f MyApp.Api/Dockerfile -t myapp-api:latest .
Running it under Windows works fine and doing an ls /app gives all the DLL/files I expect.
I then deployed to Docker Hub and tried to run it on a dev server I have under Debian 10 hosting several other containers.
However launching the app the same way doesn't give me the same result:
4aa6c81f67a1 myapp-api:latest "bash" 8 minutes ago Exited (0) 8 minutes ago dazzling_ramanujan
Strangely enough bash appears to be launched instead of dotnet.
I then commited this exited container to a new one and overrided the entrypoint in order to inspect the container and doing an ls /app shows me an empty folder while it's filled in Windows.
Did you encounter something similar? How to debug that ?

Docker run does not binding host port

I'm trying to run simplest asp.net core 3.1 WebApplication inside docker as simple as possible but, docker does not binding host port.
Host: Windows 10
Container target: Linux
Docker version: 20.10.7
Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
EXPOSE 80
EXPOSE 443
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "WebApplication.csproj"
RUN dotnet build "WebApplication.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication.dll"]
Docker build command (ok)
docker build -t webapplication .
Docker run command (ok)
docker run webapplication -p 5000:80 -p 5001:443
When I try to access website on my localhost (http://localhost:5000) I'm getting This site can’t be reached. Running the docker ps returned ports information without host mapping port
As #marzelin correctly pointed out, you need to add the flag right after run.

How do I open a site using ASP.net Core in Docker on Ubuntu on Google.Cloud?

When I run docker with Asp.net Core locally everything is ok. But when I use the Ubuntu virtual machine in cloud.google, I kind of start the container and everything works. But I don't know how to open the site. Login via External ip doesn't open anything. I just have "Can't access the site" Although everything opens locally. Am I missing any settings?
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster 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 AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Command: sudo docker run -d -p 8000:80 gamehomm/webapplication1
I got it!
docker run -d -p 80:80/tcp gamehomm/webapplication1
Then I changed VM instance details
Firewalls
Allow HTTP traffic
Allow HTTPS traffic

read application logs from logs folder after hosted using docker in linux

We have hosted .net core api in linux server using docker. so issue is reading application logs from Logs folder which we are not getting in container. our docker code is :
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 50147
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["Services/Services.csproj", "Services/"]
COPY ["Portal.Common/Portal.Common.csproj", "Portal.Common/"]
COPY ["Portal.Domains/Portal.Domains.csproj", "Portal.Domains/"]
COPY ["Portal.Business/Portal.Business.csproj", "Portal.Business/"]
COPY ["Portal.DataAccess/Portal.DataAccess.csproj", "Portal.DataAccess/"]
RUN dotnet restore "PortalServices/PortalServices.csproj"
COPY . .
WORKDIR "/src/PortalServices"
RUN dotnet build "PortalServices.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "PortalServices.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "PortalServices.dll"]
so inside app path only dll files are there. So how can we read logs from folder???
We implemented serilog to solution and saving to solutionpath/Logs/log.txt
In local it is storing in this path.
Please help!!
Change folder permission to 777 where you want to store logs.
chmod 777 .
docker run -d -t -i -p 80:80 -v /usr/Logs:/app/Logs --name
testContainer testImage

Can't start ASP.NET Core web API Docker on a specified port

Here is my Dockerfile:
FROM microsoft/aspnetcore-build:1.0 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM microsoft/aspnetcore:1.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 58912
ENTRYPOINT ["dotnet", "SgaApi.dll"]
I used this command to build: docker build -f Dockerfile -t sga .
Run: docker run -e "ASPNETCORE_URLS=http://+:58912" -it --rm sga
Application starts successfully
I can't access it from the browser. When I run the application using "dotnet run" it works fine.
You have exposed the port, but you haven't published it. You can either use -P to publish all exposed ports or -p and then specify port mapping. For example:
docker run -p 58912:58912 -e "ASPNETCORE_URLS=http://+:58912" -it --rm sga

Resources