VB.NET application cannot run on Docker - vb.net

I have a Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
and I want to be able to run a simple VB.NET application file main.vb with the code below:
'Program to print "Hello World" in VB.NET.
Module Module1
Sub Main()
Console.WriteLine("Hello World")
End Sub
End Module
I ran: vbc main.vb but I got the error sh: 1: vbc: not found
Please what do I need to do? It seems it is not possible to run it in my container.

I think your Dockerfile is missing some things.
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "VbApp.dll"]
Then running the following commands from the console will output "Hello World"
docker build -t vbapp-image -f Dockerfile .
docker create --name vbapp vbapp-image
docker start vbapp -a

Related

.net core Dockerfile issue / MSBUILD : error MSB1009: Project file does not exist

Below is the output of the Error when i build a Dockerfile
My Dockerfile seems like that :
FROM microsoft/aspnetcore-build:6.0 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM microsoft/aspnetcore:6.0
WORKDIR /app
COPY — from=build-env /app/out .
EXPOSE 80/tcp
ENTRYPOINT ["dotnet", "AuditModule.dll"]

Set Assembly version of net core app using Azure DevOps with a DockerFile

I am using a DockerFile created by visual studio to create my image. I want to build with Azure DevOps and set my assemblies version inside the image the version I have in the Pipeline. I feel that I have to change this line but I dont known how.
RUN dotnet build "ImportBatch.Api.csproj" -c Release -o /app/build
My DockerFile
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["ImportBatch.Api/ImportBatch.Api.csproj", "ImportBatch.Api/"]
COPY ["ImportBach.Dto/ImportBatch.Dto.csproj", "ImportBach.Dto/"]
COPY ["Common/Common.csproj", "Common/"]
COPY ["Common.Dto/Common.Dto.csproj", "Common.Dto/"]
COPY ["Common.Azure.Storage/Common.Azure.Storage.csproj", "Common.Azure.Storage/"]
RUN dotnet restore "ImportBatch.Api/ImportBatch.Api.csproj"
COPY . .
WORKDIR "/src/ImportBatch.Api"
RUN dotnet build "ImportBatch.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ImportBatch.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Cardinal.Software.ImportBatch.Api.dll"]
From pipeline:
- task: Docker#1
displayName: 'Build the image'
inputs:
dockerfile: 'Dockerfile'
imageName: '$(imageRepoName):$(GitVersion.SemVer)'
arguments: '--build-arg version=$(GitVersion.SemVer)'
continueOnError: true
On DockerFile:
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
WORKDIR /src
COPY . .
ARG version #define the argument
#use this argument while running build or publish, for example
RUN dotnet publish "./yourProject.csproj" -c Release /p:Version=${version} -o /app/publish --no-restore
For SDK-style projects assembly version attributes are generated automatically, so you can use p:Version=1.2.3.4 right out of the box. Please check example here (at the bottom)
dotnet build -p:Version=1.2.3.4

Docker build for C# core need the internet connection

I am writing in C# .NET core (VS 2017), using the build for linux containers, using docker-compose.
When I build the image (or publish), there is always reference to the internet, because of nuget usage.
Last error encountered (which I persume of downtime on the nuget, but no matter
- any downtime should not lead to exception in build/publish).
/usr/share/dotnet/sdk/2.1.503/NuGet.targets(114,5): error : Unable to
load the service index for source https://api.nuget.org/v3/index.json. ...
I want to build the image, even the nuget is down, or even there is no interet connection
The yml file look like this:
services:
myProj:
image: my_proj
build:
context: ./all_projects/base_solution/
dockerfile: myProj/Dockerfile
It seems that "dotnet publish..." command call restore from the internet.
If I run publish with --no-restore, the code not compiled, but I want to restore the nuget packages from my own pre-build of my computer.
How can I do it? With no internet connection? Why should I depend on the internet to restore the nuget at each build?
Why cannot I restore nuget package from my own pre-build image, and not always?! get from nuget (actually nuget packages not change occasionally in my code).
May I just copy the folder from the nuget, and not using "COPY" command?
I did the following:
Build an image from a 'common' project, that uses all the nuget package.
Add a reference in the built-image for the new other image, like this:
Create a new common image:
# there is no runtime.
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY TestDock/TestDock.csproj TestDock/
FROM build AS publish
RUN dotnet publish TestDock.csproj -c Release -o /app
And at the original image:
FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app
# FROM microsoft/dotnet:2.1-sdk AS build do:
FROM my_common_image AS build
WORKDIR /src
COPY TestDock/TestDock.csproj TestDock/
# Added the following. I tried to copy all, but this doesn't help.
# I persume I can copy part of the common build.
COPY --from=build /app /app
COPY --from=build /src /src
COPY --from=build /usr /usr
FROM build AS publish
RUN dotnet publish TestDock.csproj --no-restore --no-dependecies -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TestDock.dll"]
I have tried to add an intermediate image, with Dockerfile as following:
# This image is base image for all dockers (no need runtime)
# docker build . -f DockerFile_Common -t docker_common
FROM microsoft/dotnet:2.1-sdk AS build
COPY . .
WORKDIR /src/myProj
FROM build AS publish
RUN dotnet publish myProj.csproj -c Release -o /app
RUN dotnet pack /src/myProj.csproj -c Release -o /app
and use it in my image (that I don't want to build using the internet), instead of:
FROM microsoft/dotnet:2.1-sdk AS build
I did:
FROM docker_common AS build
I also tried to add the line: "RUN dotnet publish ..." when setting the workdir as the solution folder, and mark the "Microsoft Visual Studio Offline Packages" (unmark default "nuget.org").
Still, the above doesn't build correctly.
For not using the internet, you can follow the steps.
What is needed is to publish in visual studio, as following:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-2.2
(Alternative publish in command line).
dotnet publish myProj.csproj -c Release /p:PublishProfile=Properties\PublishProfiles\
<myprofile>.pubxml /p:PublishDir=<proj_folder>\bin\Release\netcoreapp2.1\publish
or put in the Post-build event a line like:
dotnet publish $(ProjectDir)$(ProjectName).csproj -c $(Configuration)
/p:PublishProfile=Properties\PublishProfiles\PublishProfile.pubxml
/p:PublishDir=$(TargetDir)publish --no-build
... and in the Dockerfile I just did with need to do "COPY ..." from the relevant publish directory!
FROM microsoft/dotnet:2.1-runtime
COPY MyProjectFolder/bin/Release/netcoreapp2.1/publish /app
WORKDIR /app
ENTRYPOINT ["dotnet", "myproject.dll"]

Build multi project net core image using Dockerfile

I'm using the reference: https://docs.docker.com/engine/examples/dotnetcore/#prerequisites to create the following Dockerfile:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
However I have the following solution structure:
.sln
Dockerfile
------------WebAPP
------------WebAPP.Domain
I then modified the Dockerfile so I can target my WebAPP csproj etc.
FROM microsoft/aspnetcore-build AS builder
WORKDIR /app
# copy csproj and restore as distinct layers
COPY ./WebAPP/*.csproj ./
RUN dotnet restore
# copy everything else and build
COPY ./WebAPP ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM microsoft/aspnetcore
WORKDIR /app
COPY --from=builder /app/out ./
ENV ASPNETCORE_ENVIRONMENT Production
ENTRYPOINT ["dotnet", "WebAPP.dll"]
However it fails on the dotnet publish step because it's lacking of the Domain project which can make sense. I have also added the RUN dotnet build step to make sure I had all dependencies and dlls and I did get a failure on the penultimate step:
Step 10/12 : COPY --from=builder /app/out ./
COPY failed: stat /var/lib/docker/aufs/mnt/9b7dda771a5bf433365f513a2bfe4cfae4199402b35c95d5f81c57367cdbb788/app/out: no such file or directory
Is there anything I am missing here?
If your WebApp has a reference to WebApp.Domain, you can simplify the DockerFile
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebApp.dll"]

Exposing a port other than 3000 with Express and Docker

I'm using Docker to run an Express app and everything is fine if I run it on port 3000. The Dockerfile I'm using for that is
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 3000
CMD ["npm", "start" ]
I now wanted to run it on port 3500. I adjusted the Dockerfile to
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 3500
CMD ["PORT=3500", "npm", "start" ]
and the docker run command to
docker run -p 3500:3500 me/myapp
It throws the following error
container_linux.go:262: starting container process caused "exec: \"PORT=3500\": executable file not found in $PATH"
I'm sure this is something basic but I'm new to this and couldn't find the solution by googling it. A pointer in the right direction would be very much appreciated.
You're trying to set the environment variable PORT as you would in a bash script. Docker doesn't understand that - the CMD config wants something which it can execute - a command name & some arguments.
The way to do what you want in Docker is to use ENV. In your case, it'd look something like this:
ENV PORT 3500
CMD ["npm", "start" ]
You can put the ENV anywhere in the Dockerfile, before the CMD, but it makes sense to keep a section of them later, so changes don't force a costly rebuild and more layers can be shared.