r/dotnet • u/AndyWatt83 • Jun 19 '21
.NET Development in Docker
https://andywatt83.medium.com/net-development-in-docker-6509d8a5077b?sk=69af79e1b1cc346b6e048dbeb70bc4935
u/AndyWatt83 Jun 19 '21
I've been playing around a lot recently with dev containers in Visual Studio Code - I think it's brilliant! I'm really interested to see if anyone else is using them, particularly on real world / professional projects. So far, I've just been using these on personal stuff.
6
Jun 19 '21
I like the idea. But think dotnet doesnt benefit 100% from it. Eg. It is more normal in Python to have different major/minor version issues in the framework. There IT make sense that each project have their own enviroment in docker.
But maybe it is an good way to get new developers onboarded. Only need to install IDE and docker and All your dependencies are defined.
Anyhow. I Will try it for my next project
5
u/AndyWatt83 Jun 19 '21
I totally agree that dotnet on it's own doesn't really get many massive benefits. But, many projects these days have loads of other dependencies, and for me that is where the power of this comes in.
I'm building this up one piece at a time, but this article is the start of a wee series that will end up with a 'full stack' environment built up, with Angular, multiple database platforms etc. And I think that I can maintain the super-easy onboarding thing.
3
u/seanamos-1 Jun 20 '21
We use them and they do have benefits for dotnet:
Every so often a breaking change will creep in the dotnet CLI. They can break build scripts unless you have a specific version of the dotnet CLI installed.
If you have quite a few repos, over time you will need multiple versions of the dotnet SDK installed to build those projects. Dev containers let you just open a repo without worrying about this.
You might need more than just a specific version of dotnet, maybe you need some other things as well, like a specific version of node. You can bundle this all up into a repeatable dev environment.
2
u/SpaceZZ Jun 19 '21
Basically some of the gains shown here for the dotnet are just the same as using plain Python venv or something like more advanced like poetry (dependencies control, version freezing etc).
2
u/wrasteight Jun 20 '21
They benefit in a sense that it is really easy to try out dotnet for non dotnet users without mucking up their machines with some installs that they might never use again. And its not only for dotnet there are many available containers, c++, go, java, node, python, azure cli, R, Ruby etc... This container thing is more of a VS code feature than specifically for dotnet.
9
Jun 19 '21
[removed] — view removed comment
5
u/AndyWatt83 Jun 19 '21
Have any of them been specifically asking for Dev Containers, or using Docker for their dev environments? Or just for production?
6
3
u/RirinDesuyo Jun 21 '21
One thing that I've appreciated with modern .net in general at the very least is that it has done a pretty good job of abstracting the OS imo. As a consequence you don't always have to do containers since your code in general is pretty portable. And even then it's pretty easy to put into containers when the actual need arises.
1
u/BeaconRadar Jun 20 '21
Does this advice span Linux app service, Dev teams with some on Mac/Linux?
2
u/iziizi Jun 20 '21
Running .net on azure linux app service spins up a container for you… You just deploy the .net files from CI and away you go.
4
Jun 20 '21
[removed] — view removed comment
1
u/BeaconRadar Jun 20 '21
Okay. I believe we have a similar setup.
The app service (plan) is running a VM instance under the hood on service fabric. Sharing an app service plan effectively means sharing/scaling the same 'instance'. I can see how that might be a problem for some:)
1
Mar 26 '22
I'm interested in hearing a bit more about what failures you see. I wouldn't say I'm the most experienced in Docker, but the whole point is to create from start to finish an entire environment so that there is no possibility of failure. Your development ran on the same object that the integration tests ran on and is the same environment that's being deployed to production.
I agree that C#'s build ecosystem, with self-contained runtimes, is very easy to get right, versus something like Python. However rarely are C# applications deployed in isolation, you may have dependencies on a RabbitMQ server, an NServiceBus control queue, SQL Server, a Redis cache, Kafka, whatever. Is not the point of using a Docker-based approach to configure and control all of these inter-related dependencies as a single unit?
7
u/HellraiserGN Jun 19 '21
I'm interested to see if this can be done with visual studio 2019 as well. For c# dev I still enjoy using that over code. For front end items I use vscode.
4
u/AndyWatt83 Jun 19 '21
Yeah, this would be cool if it worked in 'full' Visual Studio as well. I quite like VSCode for C#, but it's definitely still not as slick a set up as just using Visual Studio.
I'm working on adding an Angular front end to this project, and I think it will start to make a bit more sense when more and more dependencies start to appear
3
u/devcp Jun 20 '21
You can use visual studio to debug and run the app in a container (I set it up to work in docker-compose)
https://docs.microsoft.com/en-us/visualstudio/containers/tutorial-multicontainer?view=vs-2019
3
u/HellraiserGN Jun 20 '21
That I've done.. but to have an entire project in docker so new devs on my team aren't fighting dependency issues with the obscure projects would make it so much nicer. Every time we have to onboard a new person or have someone look at one of the projects we're still supporting, it would be nice to be able to just do it this way and get them up and running asap. Thanks for the link to remind me though. I need to save that for reference again.
19
u/porridge111 Jun 19 '21
I found dotnet dev in vscode a bit cumbersome. Omnisharp crashing all the time. Switched to JetBrains rider.
3
u/AndyWatt83 Jun 19 '21
Jetbrains are working on this as well - I'd expect that they will have a very similar offering before too much longer.
2
u/hariharan618 Jun 20 '21
How does this work very well with solutions that has various cloud services and a separate UI app in Angular or react ?
2
u/AndyWatt83 Jun 20 '21
It works okay with Angular. The challenge with Angular is running the Karma / Protractor tests, which use a browser on the host machine. I am working on a post explaining how this works - watch this space!
Cloud services work quite well. You need to run each service (or mocks) in it's own container, and use Docker Compose to orchestrate it.
29
u/brickville Jun 19 '21
Absolutely are. We have been converting our old IIS (C# WCF) web services to .net core docker/kubernetes over the past few years. Loads of advantages over the old tech.