Distros like Ubuntu 22.04 only supports OpenSSL 3, so users can only install .NET 6 SDK, it does not support .NET Core 3.1 or 2. Fortunately, Microsoft officially provides image files for development, and we don't even need to write Dockerfile to set up the environment.
Setup Environment
Here are the instructions to start a container named dotnet31
locally using devcontainers/dotnet:dev-3.1
:
$ mkdir -p dev-container/dotnet31
$ cd dev-container
$ docker pull mcr.microsoft.com/devcontainers/dotnet:dev-3.1
$ docker run -it --name dotnet31 --volume ./dotnet31:/workspace:cached --network host mcr.microsoft.com/devcontainers/dotnet:dev-3.1 sleep infinity
Notice that we use --network host
, that makes the container share the host’s networking namespace. So be careful to do any network change inside the container. You can omit the option if you don't need to access localhost from the container.
Next, enter the container to test whether the program can be compiled and executed:
$ docker exec -it dotnet31 bash
Inside the container:
# dotnet --list-sdks
3.1.425 [/usr/share/dotnet/sdk]
# mkdir /workspace/test && cd /workspace/test
# dotnet new console
# dotnet run
Hello World!
Then use your favorite IDE or editor to enter the container development, I personally use VS Code's Dev Containers.
Other settings
Notice that you may need to manual use --environment=Development
to tell the compiler using development settings.
# dotnet run --environment=Development
You may also need to set up Entity Framework.
# dotnet tool install --global dotnet-ef --version 3.1.3
Finally, you can also install other packages.
# sudo passwd root
# sudo apt install neofetch
Hope this to be helpful for who annoyed at developing old .NET projects in new Ubuntu host systems.
Top comments (3)
I love docker and made it using docker-compose.
That's greate, thanks! I prefer to make it as simple as possible, so I didn't make a docker-compose.
@blueskyson any sample ?