Last post Dec 11, 2017 04:07 PM by bruce (sqlwork.com)
Dec 02, 2017 03:52 PM|FatMooseHenry|LINK
What is the best way of setting up a development environment using .net core and docker? From the examples I've seen, it seems that you have to redeploy everything everytime you make a code change. I'm trying to get a setup where I can do development in visual
studio code + docker with debugging and without having to compile and restart the docker container
I had hoped that i could mount my local project so that docker would read the files that I work in, but I have a bit of problems with getting everything to work.
I've created a new project:
`dotnet new httpapi`
which creates a working project with a docker file:
FROM microsoft/aspnetcore-build:1.0-2.0 as BUILD
COPY ./ /apps
RUN bash -c "dotnet restore ./MountAndWatchTest.csproj && dotnet publish ./MountAndWatchTest.csproj -c Release -o ./obj/Docker/publish"
COPY --from=BUILD /apps/obj/Docker/publish .
ENTRYPOINT ["dotnet", "MountAndWatchTest.dll"]
I have tried to:
- Mount the src directory from docker-compose
- change the docker file to:
RUN dotnet restore
RUN dotnet run
The idea is to change it to "dotnet watcher run" later and hopefully get it to update on code changes.
I'm able to run 'dotnet run' locally and get a server up and running on port 5000, but when I do it in docker I get a:
'Couldn't find a project to run. Ensure a project exists in /src, or pass the path to the project using --project.'
even though it works locally.
Firstly: Am I on the right path, or is there a better way to develop through a docker container? Or should I develop locally and move it to a container at deploy time? In that case I'm worried about the environment not being the same as that is running on
Dec 04, 2017 12:19 AM|bruce (sqlwork.com)|LINK
you have a couple options:
normally you would mount a host folder as a docker volume. then add this volume to the application engine. then you could access the volume externally. On windows I'm not sure the a file watcher in the docker image will detect changes.
another option is to add ftp to the docker container, so you can ftp files to the docker image.
you can just use the visual studio default of building a new docker image every time you compile.
Dec 05, 2017 07:33 PM|FatMooseHenry|LINK
Thanks for your answer, I have tried to mount the volumen (through docker-compose) and change my docker file to:
RUN dotnet run
But I am getting a:
Couldn't find a project to run. Ensure a project exists in /src, or pass the path to the project using --project.
even though, I can run the project locally just fine (going into the src folder an execute 'dotnet run')
The files are mounted correctly in the src folder, but cant seem to be able to start it.
Would you start the project through by 'RUN dotnet run' asI have, or would you do it any other way?
(And by the way, this in on Ubuntu)
Dec 06, 2017 10:10 AM|Edward Z|LINK
Could you share us your current complete compose file and docker file?
I suggest you make a test with below:
Dec 08, 2017 07:48 PM|FatMooseHenry|LINK
Thank you for your answer, you got me a bit more on the right track. I moved my files to "app" instead of src in the docker container, and now I'm able to run the project with:
--DockerFileFROM microsoft/aspnetcore-build:1.0-2.0WORKDIR /appEXPOSE 80ENTRYPOINT ["dotnet","run"]--Docker-compose:version: '3'services: api: image: mountandwatchtest build: context: ./src dockerfile: Dockerfile hostname: src restart: always environment: - ASPNETCORE_ENVIRONMENT=Production ports: - "8080:80" volumes: - ./src:/app logging: driver: json-file options: max-size: "10m" max-file: "5"
So... next step is to try to get the code to "reload" whenever I change a file. Therefore I added:
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
to my csproj file, and changed my DockerFile to:
But I run into the errors:
Version for package `Microsoft.VisualStudio.Web.CodeGeneration.Tools` could not be resolved.
Version for package `Microsoft.DotNet.Watcher.Tools` could not be resolved.
I'm digging a bit more into how to resolve this, but let me know if you have any good ideas :)
Dec 09, 2017 06:39 PM|bruce (sqlwork.com)|LINK
Dec 10, 2017 05:27 PM|FatMooseHenry|LINK
I want to be able to do development in the docker container directly without having to manually compile and restart the container each time I do a code change.
The idea is to have a "development" container that should automatically reload the changes I make to the code, so that I can develop on an environment as close to the production environment as possible. I would then have a "production" docker image that instead
copies the code into the container so it can be deployed on a server.
That way IIS config etc would be applied to both the production and the development container, so that the only difference between the two, is that the development container automatically loads code changes without having to restart the container. When running
"dotnet watch run" in the development container I would only have to start up the continer once, and then the code changes would be loaded automatically.
Is there a better way of doing this? Or is people generally developing on their own machine and then copy the code to docker for production releases?
Dec 11, 2017 04:07 PM|bruce (sqlwork.com)|LINK
once you get dotnet watcher installed in the docker image, you will need to edit the files inside.
you can create a docker volume image and mount in your dev docker image, but on windows, you may find that watcher doesn't work (as its really a network share under the covers).
a workaround would be a script that copies the files from the share folder to source folder or use ftp.
if you are using a linux container rather than windows container, i'd create a linux VM, to dev in. (well, I dev on a mac, so I just use osx rather rather than the windows vm).
but your second assumption is correct. Most dev native, and only use docker for integration testing.