I'm using dotnetcore to develop applications and one thing I noticed when creating a aspnetcore (2.1) web api was the option to "Enable Docker" on the project. See below:
This was really great for allowing me to run my web application against my local docker for debugging! :-DI see that I have a new .dcproj file for the docker project, a docker file in my web api and a yml file in the docker project. Everything I needed to run in debug.
Now I'm creating a dotnetcore console application (again core 2.1 is the version I'm using). Unfortunately, I dont have an "Enable Docker Support" option for console apps and would like to run my console app in my local docker instance. Visual studio version I'm running is as follows:
I had a look for and can't seem to find the docker project as a project type template. So I resorted to copying over the docker project from my web app and modifying it to run my console app... needless to say I'm not able to get this running. I get the following error when I try to launch the docker compose:
Failed to launch debug adapter
My docker file is identical to the one from the web project (that works), other than my project and dll names (these are set correctly).
My yml file is the same also, other than the names being changed also. Not sure what I'm doing wrong - has anyone managed to achieve this? I ultimately want to debug my console application when it's running in docker through Visual Studio debug.
Thanks for any pointers in advance!!
For verbosity, here's my Dockerfile :
FROM microsoft/dotnet:2.1.2-runtime-alpine3.7 AS base
WORKDIR /app
EXPOSE 52649
EXPOSE 44331
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY AI.EmitterJob.csproj AI.EmitterJob/
RUN dotnet restore AI.EmitterJob/AI.EmitterJob.csproj
COPY . .
WORKDIR /src/AI.EmitterJob
RUN dotnet build AI.EmitterJob.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish AI.EmitterJob.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "AI.EmitterJob.dll"]
And docker-compose.yml file:
version: '3.4'
services:
ai.emitterjob:
image: ${DOCKER_REGISTRY}ai_emitter
build:
context: .
dockerfile: ../AI.EmitterJob/Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_HTTPS_PORT=44331
ports:
- "52649:80"
- "44331:443"
volumes:
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
Note - I know I dont need to expose ports or use volumes here (or set env vars) for the console app, but I wanted to keep changes from the web docker file that works, to a minimum.
Just in case anyone else wants to try this, I finally got it working!
When I copied over the docker file, the only line I changed was from this:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
To this:
FROM microsoft/dotnet:2.1.2-runtime-alpine3.7 AS base
Because I'd used that alpine build before as a base image. Reverting back to the aspnetcore base image made this work fine.
Obviously, this isn't ideal for proper deployments and I need to find a sufficient replacement for the aspnetcore base image that will have the dotnetcore runtime installed.
I'm happy I can debug my console app through docker now! :-D
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.