working my way through tutorials on dockerized the API WeatherForecast web template from ASP.NET core:
I had to start from here, because I wasn’t getting a new image to build using the tutorial here: https://docs.docker.com/compose/aspnet-mssql-compose/
“1” works, which is great. However, “2” will not work on the
localhost:5000/WeatherForecast port as advertised, and I’m having some trouble debugging why after many reviews of the available docs.
I should make a note that in creating the templated app from the command line, I did choose the –no-https option.
I then used docker ps to bring up the PORTS . The web app is using
5000/tcp, 0.0.0.0:32779->80/tcp . When I substitute
32779 , I get the API string returned instead!
I know I’m missing something within docker-compose and could use some extra eyes on it. Thank you!
EDIT: For reference, the files below were generated by my VSCode editor.
1. I ran dotnet new webapi –no-https
2. I then brought up the VSCode “command pallete” and ran
Docker: Add Dockerfiles to Workspace and selected ‘yes’ for the inclusion of docker-compose.yml file and Linux. I also choose to use port
5000. I use Fedora 30.
4. I run
dotnet build from the project root in the terminal.
5. If I run from
docker commands and make the ports explicit it will work as advertised, but if I run
docker-compose -f <yml-file> up -d- --build, it will not.
I just re-read this and find it annoying that I’m stuck within VSCode to fix the issue (according to the docs)
By default Docker will assign a randomly chosen host port to a port exposed by a container (the container port). In this case the exposed (container) port is 5000, but it will be exposed on the host via a random port, such as 32737.
You can use specific port on the host by changing the Docker run options used by docker-run: debug task (defined in .vscode/tasks.json file). For example, if you want to use the same port (5000) to expose the service, the docker-run: debug task definition would look like this:
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service. version: '3.4' services: aspdotnetdocker2: image: aspdotnetdocker2 build: context: . dockerfile: Dockerfile ports: - 5000
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base WORKDIR /app EXPOSE 5000 FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build WORKDIR /src COPY ["aspdotnet_docker2.csproj", "./"] RUN dotnet restore "./aspdotnet_docker2.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "aspdotnet_docker2.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "aspdotnet_docker2.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "aspdotnet_docker2.dll"]