I'm trying to run my dotnet 5 single file app with Alpine Linux docker image.
This is my Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine
WORKDIR /app
COPY ["Service.Translations", "/app/Service.Translations"]
CMD ["./Service.Translations", "--urls", "http://0.0.0.0:5000"]
This was framework-dependent app. Also tried with self-contained and result is the same:
not found. Dotnet doesn't see my file and sh doesn't see too.
Is it problem because I built my app on Windows? All tutorials with alpine compile app inside image. If I change Alpine to Ubuntu or smth else - everything is ok.
UPDATE:
Ok, problem was with publish. I had to change --runtime to linux-musl-x64 instead of linux-x64
I found the problem. Alpine Linux uses musl c library and it makes standard dotnet build incompatible with this linux distro. Visual studio doesn't have all publish runtime options. Here https://learn.microsoft.com/en-us/dotnet/core/rid-catalog you can find all of them. So for alpine linux we have to use linux-musl-x64 runtime instead of linux-x64
Related
Turbo crashes when using any command (e.g. turbo build), even when a valid project and turbo.json exists. This doesn't seem to be a problem on Ubuntu, but only on Alpine (arm64).
I've tried all of the new versions but they have the same issue.
npm install --global turbo
npm install --global turbo#latest
npm install --global turbo#canary
error:
thread 'main' panicked at 'Failed to execute turbo.: Os { code: 2, kind: NotFound, message: "No such file or directory" }', crates/turborepo/src/main.rs:23:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Because I was stuck on this for a few hours, I'll share solution here (which I also shared on Github):
If using a Dockerfile: add RUN apk add --no-cache libc6-compat to it
If using it on an Alpine machine, run apk add --no-cache libc6-compat
More explanation in:
Docker Node image docs
Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.
The main caveat to note is that it does use musl libc instead of glibc and friends, so certain software might run into issues depending on the depth of their libc requirements.
One common issue that may arise is a missing shared library ... . To add the missing shared libraries to your image, adding the libc6-compat package in your Dockerfile is recommended: apk add --no-cache libc6-compat
https://github.com/vercel/turbo/issues/3373#issuecomment-1397080265
I'm absolutely new in Docker and Jenkins in addition that I am sophomore at software world. Firstly, I would like to describe our system. We are using Centos 7 and I installed Jenkins on Docker as a container. After that I have tried using the Dotnet commands such as dotnet build on Jenkins, but I faced some errors(" dotnet: not found "). I guess I must install dotnet sdk for jenkins on docker by using Dockerfile. But I could not create Dockerfile properly. I got always some error. Can you share Dockerfile or similar issue for me.
After a quick search i have found this Dockerfile and also this post
This could do for you. I think you should be able to salvage useful bits for yourself.
But if there is an option id recommend your Jenkins agent just run the docker build of the dedicated .net core container through the docker socket? (as an idea of course). For reference
I am trying to publish my dotnet project-api from jenkins via powershell. The problem is when I publish it from powershell it's missing around 30 files and I can't reach api. However when I publish it from visual studio manually (or from visual studio package manager console with commands) it works perfectly. What might be causing this issue?
Here are the commands that I am running to publish api ;
dotnet restore
dotnet build --configuration release
dotnet publish -c release --output "path to the publish file"
I have also tried with this to publish command yet it didn'T work;
dotnet publish dotnet publish -c Release --self-contained -r win10-x64
I have been trying to figure this issue for a long time but I couldn't find a way. I would highly appreciate any help. Thanks!!
You should try following 2 Execute Windows batch command
Command
"C:\Program Files\dotnet\dotnet.exe" restore yourProjectSLN file
[E.g:yourProjectSLN = git/FolderName/ProjectName.sln , it should be same as jenkins configuration]
Command
dotnet publish yourProject_csproj_file_location -c:Release
[E.g:yourProject_csproj_file_location = git\FolderName\ProjectName.csproj]
I’m developing a DotNet Core hosted Blazor WebAssembly, as a frontend to my backend ASPNet Core API, running on Raspberry Pi’s, containerised in a Docker Swarm.
I’m developing on a MacBook Pro, using VSCode for Mac, and it’s really a great tool. I created the solution as “dotnet new blazorwasm —hosted” and got the solution created and build.
I have installed Docker Desktop, and created a Buildx builder for arm, which works great with all my other solutions (DotNet Core API, DotNet Background solutions), but with the hosted blazorwasm solution, I run into several problems, probably caused by my lacking knowledge on setting up build options.
So I installed Visual Studio 2019 (I have used VS on Windows for 20 years) and was actually surprised over the look and feel, a really great tool.
I created the hosted Blazor WebAssembly solution, which works great om Mac, and even the Docker desktop integration work without problems.
Building the Docker Image was easy, I just used my Buildx builder, and executed below command from the command line:
“docker buildx build --file ./SnakeConsole/Server/Dockerfile --platform linux/arm/v7 -t jagdriver/wavesnake:SnakeConsole3 --push .”
On the Raspberry Swarm, I then created the Stack/Container. The Stack installed but the container refused to start, and the log was:
standard_init_linux.go:211: exec user process caused “exec format error”.
I have seen this error before, and as far as I remember I added “-r ubuntu.19.10-arm” to the dotnet publish command to ensure that the code is generated for linux-arm.
So I tried to add “-r ubuntu.19.10-arm” to the dotnet publish command in below dockerfile, and execute the Docker buildx build command again, but then the Build Engine run into below error.
project.assets.json' doesn't have a target for '.NETCoreApp,Version=v5.0/browser-wasm'. Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project. You may also need to include 'browser-wasm' in your project's RuntimeIdentifiers
Can anyone out the give me a helping hand on this, thanks in advance.
FACTS:
The solution I’m mentioning is the standard Hosted Blazor
WebAssembly template without any changes.
The target framework is .Net 5.0
Visual Studio for Mac community is version 8.7.2 (build 4)
Docker file from the default hosted Blazor WebAssembly template.
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY SnakeConsole/Server/SnakeConsole.Server.csproj SnakeConsole/Server/
COPY SnakeConsole/Client/SnakeConsole.Client.csproj SnakeConsole/Client/
COPY SnakeConsole/Shared/SnakeConsole.Shared.csproj SnakeConsole/Shared/
RUN dotnet restore "SnakeConsole/Server/SnakeConsole.Server.csproj"
COPY . .
WORKDIR "/src/SnakeConsole/Server"
RUN dotnet build "SnakeConsole.Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SnakeConsole.Server.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SnakeConsole.Server.dll"]
Have faced similar issue, documentation says:
Deploying a standalone Blazor WebAssembly app to Azure App Service for Linux isn't currently supported. A Linux server image to host the app isn't available at this time. Work is in progress to enable this scenario.
https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-5.0#standalone-deployment
Looks like this is a Docker OS compatibility and framework functionality issue. I would suggest to target your app to Server (Blazor Server Hosting model scenario).
Assuming this folder structure
SampleApp
global.json
Src
Web
project.json
Startup.cs
...
Model
project.json
Startup.cs
...
how does one compile both projects using dotnet? (from command line, not in visual studio)
If you run dotnet build at the root folder level you get
Could not find file .. project.json
I can see there is this outstanding enhancement on the CLI repo but that is from Feb2.
Any script would have to take dependencies into account before just blindly calling dotnet on all src sub-folders.
The dotnet build command accepts glob patterns. So you can do this:
dotnet build Src/**/project.json
There's no such a tool yet. Even KoreBuild, the tool that the ASP.NET team uses, goes blindly in each folder and invokes dotnet build/pack.
The nice thing is that dotnet build is now smart enough to not recompile the dependencies if they haven't changed, so that's not a problem anymore.
For linux I'm using:
for p in $(find . -name *.csproj); do dotnet build $p; done
I had a similar requirement. This is my workaround:
#echo off
for /D %%d in (*) do (
cd %%d
cd
dotnet restore
dotnet build
cd ..
)
exit /b
Use GNU Make. I use it to build my projects. all you have to do create a Makefile in your project root folder. You can nest Makefiles in directories and have a Top Level Makefile that runs the subdirectories. then you set up Makefiles for each of your "Sub Projects" folders and run any comandline tool. with dotnet core is is dotnet .
Wait... GNU - "GNU is not Unix" that's a Unix/Linux application... I run windows. Well the good news is you can do this is in windows. I'm using make.exe through my git-bash installation (git for windows). You will have to go find the cygwin port of make. (google: "make for git-bash") Then install it to your bin directory under the cygwin folder. You could also just install cygwin if you really wanted to.
The nice thing about using Gnu-Make is it is universal. Since dotnet core is platform agnostic, every environment Mac/FreeBSD/Linux have "make" most likely already installed. Adding it to your Windows machine and projects to me makes a lot of sense. Since you project can now be built by everyone the same way.
some of my projects need to build docker containers with dockerfiles, or snap packages, deploy to test, etc... Make (pardon the pun) makes it easy.
Here is a sample of simple projects Makefile. Running 'make' by itself is like saying 'make all' you could set up a command like 'cd ./subdir; make' as one of your .phoney directives. (Google: "Makefile documentation")
project_drive?=/c/prj
nuget_repo_name?=Local_Nuget_Packages
local_nuget_dir?=$(project_drive)/$(nuget_repo_name)
RELEASE_VERSION:= `grep "<Version>" *.csproj | cut -d '>' -f 2 | cut -d '<' -f 1`
.PHONEY: clean release test doc nuget install debug_nuget debug_install
all: doc MSBuild
test:
./test.sh
MSBuild:
dotnet build
clean:
dotnet clean; dotnet restore
release:
dotnet build -c Release
doc:
doxygen ./Doxyfile.config
nuget: release
dotnet pack -c Release
install:
cp ./bin/Release/*.$(RELEASE_VERSION).nupkg $(local_nuget_dir)
debug_nuget: MSBuild
dotnet pack
debug_install:
cp ./bin/debug/*.$(RELEASE_VERSION).nupkg $(local_nuget_dir)
What's missing is that you can also use the commands on project.sln files if you do not have project.json
dotnet build src/**/project.json
-- or --
dotnet build src/project.sln
same goes for dotnet test