I have recently tried to do some C# development on my Linux box with the help of the docker image microsoft/dotnet which works great within the docker image.
Yet I would like to use Visual Studio Code with the C# extension powered by OmniSharp to get intellisense/autocompletion, and the other benefits of that extension within that editor.
The problem is that .NET Core is not supported on my distribution (Arch). There is an AUR package but it has been more often broken than working and I would rather stick with my docker image to run dotnet in a container.
Hence my question is: can I make Visual Studio Code's C# extension which is running on my host OS use the dotnet tools available in the docker image?
Thanks
Yep, you can hook your C# code in the container via Docker Volumes. Try something like this:
docker run --name app -d -p 5000:5000 -v <your-project-path>:/app microsoft/dotnet
Note: Make sure that you are using the .NET Core SDK image.
Related
I am trying to run my selenium tests in Docker but I don't see any containers running and don't see anything in the docker logs.
I have created 3 different versions of DockerFiles which can be found in https://github.com/devanasri/googlesearchauto
The commands I am using to create image and start container is
docker build -t googlesearchauto .
docker run -it automation
When run above commands to start the container and run selenium tests, nothing happens and sometimes I get below error when trying to start the container.
The command could not be loaded, possibly because:
* You intended to execute a .NET application:
The application 'test' does not exist.
* You intended to execute a .NET SDK command:
No .NET SDKs were found.
Download a .NET SDK:
https://aka.ms/dotnet-download
Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
I tried to run each version of the DockerFile but all of them not working. Any help is appreciated.
I'm facing the issue that a .Net Core WPF application automatically opens a console window when started. This only happens when build inside a Docker container. When I build it directly on my PC, only the actual application window opens.
My best guess is that this is an issue with the operating system the .Net Core image is based on. The .Net Core SDK Docker Hub Repo knows the following tags: 3.1-nanoserver-1809, 3.1-nanoserver-1903, 3.1-nanoserver-1909, 3.1-nanoserver-2004, 3.1-nanoserver-2009. I was able to confirm the issue with the first three tags, but the 2004 and 2009 tags do not run on my machine, so I need someone to try this out and either confirm my theory (which would mean that it should not happen on at least on of these images) or to come up with a better explanation of why this is happening.
This is reproducible with the default .Net Core WPF app Visual Studio creates for you. Here is a Dockerfile to test it out:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY . ./
RUN dotnet build -c Debug -o out
FROM stefanscherer/chocolatey
WORKDIR /app
RUN choco install -y 7zip
# Depending on your project setup it might be src/[project name]/out
COPY --from=build /src/out ./test
RUN 7z a -y test.zip ./test/*
You can build the image and extract the compiled program with the following commands:
docker build -t testimage .
docker run -d --name testcontainer testimage
docker stop testcontainer
docker cp testcontainer:app/test.zip .
I was able to reproduce this problem on both 3.1-nanoserver-2009 and 3.1-nanoserver-2004 for you.
I think the problem is related to the warning printed out during build:
warning NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server).
If that's the case, then it seems that it is a limitation of the nanoserver base image, and unfortunately it looks like this problem still has not been resolved, because it's still present when building in mcr.microsoft.com/dotnet/nightly/sdk:5.0.
Here's a related pull request that might shed some light on the subject.
Having said that, I think the only option for now is to use windows image other than nanoserver (alternatives can be found here). I didn't find any image that would come with .NET Core SDK preinstalled (I didn't put much effort into finding it though), but it should be fairly simple to set it up. In the following example I used servercore image since it is much more lightweight than windows image.
FROM mcr.microsoft.com/windows/servercore:20H2 AS sdk
WORKDIR /dotnet
# Download the official .NET Core install script
RUN powershell -c "Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1"
# Run the install script
RUN powershell -c "& ./dotnet-install.ps1 -InstallDir ."
# Add the installed executable to PATH
RUN setx PATH "%PATH%;/dotnet"
FROM sdk AS build
# Do your stuff here
Here you'll find the documentation for the install script.
I also did confirm that the produced application did not spawn console window when run.
As #Grx70 mentioned, the underlying nanoserver image is the problem.
There is another .NET core image, but it is based on the servercore image.
This saves the manual installation of .NET Core within the image and has everything ready at hand.
Here you can find all version of the .NET Core Image:
DockerHub
Way down at the bottom, you'll find the heading Windows Server Core 2019 amd64 Tags and the associated mcr.microsoft.com/dotnet/sdk:5.0-windowsservercore-ltsc2019 image.
This image no longer produced a console window when I built something :)
On windows 10 Enterprise. Docker version 2.3.0.4 community. Using visual studio 2019. Simple asp.net core project with docker support.It builds ok. Using windows container. Then running in Docker, I get:
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not
found.
In the Dockerfile I have:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1803 AS base
On the PC I have in the folder C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App, a folder '3.1.0' with this version of the framework.
In Powershell, I have tried pulling the framework, with the following result.
docker pull mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1803
3.1-nanoserver-1803: Pulling from dotnet/core/aspnet
Digest: sha256:3b4383b72b53a00895267571d08e9591eab1b914f35b2c2c4a2413d178eca089
Status: Image is up to date for mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1803
mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1803
So I really don't understand why docker can't find it.
Microsoft has stopped the support for nanoserver, this will end in nov. And there is no image with tag mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1803 even though VS2019adds this by default for windows containers.
Better switch to linux and proceed
reference:
https://github.com/dotnet/dotnet-docker/issues/1469
https://github.com/dotnet/dotnet-docker/issues/1698
I'm using Visual Studio 2017 to create a .Net Core Console application. I want to host this application as a Docker container (for Linux). As soon as I add the Docker support to the project, Visual Studio will run the debug within Docker, which I guess is nice since I can make sure the application behaves similar to production.
However, when debugging this way, i loose the ability to do edit/continue and basic debugging capabilities such as "Set next statement". Is there some way to get these capabilities for a Docker console app, or alternatively run the console app as a normal .Net core app while developing and only switch to Docker for some final testing?
I have run through the boot2docker virtual machine setup tutorial in the docker toolbox https://www.docker.com/toolbox.
Using window 10 as my base, I managed to get virtualbox running from kitematic with Linux default 4.0.9-boot2docker
When I start trying to run apt-get or yum to install things like NODE.JS or ASPNET I'm told that the files aren't found.
The end goal is to be able to run my aspnet docker images on my local environment.
Do I need to install aspnet, node, etc... on my docker server before I can start running aspnet docker images? If yes, how do I install them in the version of linux that has no apt-get or yum?
edit - note it is the ASPNET core documentation that seems to suggest I need to install things on the docker server. https://dotnet.readthedocs.org/en/latest/getting-started/installing-core-linux.html perhaps I can docker-build within the windows environment and docker-run from the linux VM without actually installing anything other than my docker image?
With docker you can focus on using application, not installation.
you needn't waste time on application installation that you can pull the image directly to get node.js or aspnet environments work in minutes.
So answer your question, you can have these environments ready via pull command:
docker pull node
docker pull microsoft/aspnet