Reputation: 1703
How do I create a docker container that will run .NET with hot reload via dotnet watch run
? Most of the solutions online go the right way but there is always something wrong like:
"watch" is not something dotnet can run
Upvotes: 2
Views: 728
Reputation: 1703
First of all run dotnet new webapi -o YOURPROJECTNAME
to setup the development environment with a mock api controller.
Then place this docker-compose.yml file in your root:
version: "3.4"
services:
app:
image: YOURIMAGENAME
build:
context: .
dockerfile: ./Dockerfile
ports:
- 8080:8080
volumes:
- .:/app
depends_on:
- db
Then add this Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal
WORKDIR /app
COPY . /app
RUN dotnet restore
ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "http://*:8080" ]
Then add this .dockerignore:
bin
obj
After all this is done run docker-compose up
to run the container and voila, have fun developing APIs with .NET in a container with hot reload!
Upvotes: 5