Run docker inside docker - docker

I have some dll (.net core app that can be run on linux) that does database migrations.
It receives few arguments one of them being dll that contains my applications database migration.
I created one image of all (migration application and my project that contains migration, EF core migrations) this and run them using docker run -e Server=xxx -e DatabaseName=xxx -e UserId=xxx -e Password=xxx migrate:v0.3.5
This is my docker image:
#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/aspnet:5.0-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["ef-migrations-cli/EfMigrationsCLI/EfMigrationsCLI/EfMigrationsCLI.csproj", "ef-migrations-cli/EfMigrationsCLI/EfMigrationsCLI/"]
RUN dotnet restore "ef-migrations-cli/EfMigrationsCLI/EfMigrationsCLI/EfMigrationsCLI.csproj"
COPY . .
WORKDIR /src
COPY ["RED.Database.Server/RED.Database.Server.csproj", "RED.Database.Server/"]
COPY . .
WORKDIR "/src/ef-migrations-cli/EfMigrationsCLI/EfMigrationsCLI"
FROM build AS publish
RUN dotnet publish "EfMigrationsCLI.csproj" -c Release -o /app/publish
WORKDIR /src
WORKDIR "/src/RED.Database.Server"
FROM build AS publish2
RUN find /src/RED.Database.Server/RED.Database.Server.csproj -name *.csproj
RUN dotnet publish "/src/RED.Database.Server/RED.Database.Server.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish2 /app/publish .
COPY --from=publish /app/publish .
ENV Server "please_set_Server_env_variable_when_docker_run"
ENV DatabaseName "please_set_DatabaseName_env_variable_when_docker_run"
ENV UserId "please_set_UserId_env_variable_when_docker_run"
ENV Password "please_set_Password_env_variable_when_docker_run"
ENV DatabaseContext "REDDatabaseContext"
ENV MigrationsAssembly "RED.Database.Server.dll"
ENTRYPOINT [ "sh", "-c", "dotnet EfMigrationsCLI.dll --userid=${UserId} --password=${Password} --databasename=${DatabaseName} --server=${Server} --databaseContext=REDDatabaseContext --migrationsAssembly=${MigrationsAssembly}" ]
I would like to separate my migration dll as separate docker image (because it will not change very often , or ever) and have another image that builds my project that contains migrations and pass it to the first container.
How to achieve this?

I don't understand if you want to build an image in a container OR fetch an image inside your container BUT
I think you can watch this https://hub.docker.com/_/ubuntu in the Locales chapter, you can see that it is possible to run apt-get command to install https://docs.docker.com/engine/install/ubuntu/
So I suppose, you can
RUN apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update && apt-get install docker-ce docker-ce-cli containerd.io
RUN docker run hello-world
Then you "just" have to adapt to your needs.
Hope it is a good track for you to follow

Related

dotnet build not working inside the container

Since container is not building with the full project I commented docker file as bellow . then I executed manually dotnet build command inside container. it failed like below. But when I build the container from outside from the visual studio it is building fine.
Determining projects to restore...
All projects are up-to-date for restore.
myapp -> /app/build/myapp.dll
myapp -> /app/build/myapp.Views.dll
/bin/sh: 2: /tmp/tmped91456469694a38bc5ed8e7d4b423b1.exec.cmd: docker: not found
/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/1.11.1/build/Container.targets(97,5): error : Docker is not installed or is not in the current PATH. [/src/myapp/myapp.csproj]
Build FAILED.
/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/1.11.1/build/Container.targets(97,5): error : Docker is not installed or is not in the current PATH. [/src/myapp/myapp.csproj]
0 Warning(s)
1 Error(s)
Here is the 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/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
RUN apt-get update && \
apt-get install -y wget && \
apt-get install -y gnupg2 && \
wget -qO- https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y build-essential nodejs
COPY ["myapp/myapp.csproj", "myapp/"]
COPY ["myapp/NuGet.Config", "myapp/"]
RUN dotnet restore "myapp/myapp.csproj" --configfile myapp/NuGet.Config
COPY . .
WORKDIR "/src/myapp"
#RUN dotnet build "myapp.csproj" -c Release -o /app/build
#FROM build AS publish
#RUN dotnet publish "myapp.csproj" -c Release -o /app/publish
#FROM base AS final
#WORKDIR /app
#COPY --from=publish /app/publish .
#ENTRYPOINT ["dotnet", "myapp.dll"]
ENTRYPOINT ["tail", "-f", "/dev/null"]

How to Install an application to the main docker file

I'm new to Docker. Hopefully a someone can answer the question.
I'd like to have a container with Azure functions runtime as well as mruby installed on it.
I do have scripts for both, but don't know how to combine them
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["FunctionApp1/FunctionApp1.csproj", "FunctionApp1/"]
RUN dotnet restore "FunctionApp1/FunctionApp1.csproj"
COPY . .
WORKDIR "/src/FunctionApp1"
RUN dotnet build "FunctionApp1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "FunctionApp1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
and a ruby one from https://github.com/nacyot/docker-programming-languages/blob/master/ruby-mruby-1.0.0/Dockerfile
FROM nacyot/ruby-ruby:2.1.2 as extra
WORKDIR /opt
# Install base packages
RUN apt-get install -y bison
# Install mruby
RUN wget https://github.com/mruby/mruby/archive/3.0.0.zip
RUN unzip 3.0.0.zip
RUN mv mruby-3.0.0 mruby
RUN cd mruby; make
RUN bash -c "ln -s /opt/mruby/bin/{mirb,mrbc,mruby} /usr/local/bin/"
Seems to be a very basic task, but I cannot find a solution.
It has to be a dockerfile - to debug my Azure functions app with a mruby presence
Thanks.
Found something that works. COPY by trial and error
FROM nacyot/ruby-ruby:2.1.2 as extra
WORKDIR /opt
# Install base packages
RUN apt-get install -y bison
# Install mruby
RUN wget https://github.com/mruby/mruby/archive/3.0.0.zip
RUN unzip 3.0.0.zip
RUN mv mruby-3.0.0 mruby
RUN cd mruby; make
RUN bash -c "ln -s /opt/mruby/bin/{mirb,mrbc,mruby} /usr/local/bin/"
FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["FunctionApp1/FunctionApp1.csproj", "FunctionApp1/"]
RUN dotnet restore "FunctionApp1/FunctionApp1.csproj"
COPY . .
WORKDIR "/src/FunctionApp1"
RUN dotnet build "FunctionApp1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "FunctionApp1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
COPY --from=extra /root/.rbenv /root/.rbenv
COPY --from=extra /usr/local/sbin /usr/local/sbin
COPY --from=extra /usr/sbin /user/sbin
COPY --from=extra /usr/local/bin /usr/local/bin
COPY --from=extra /usr/bin /usr/bin
COPY --from=extra /sbin /sbin
COPY --from=extra /bin /bin
COPY --from=extra /lib/x86_64-linux-gnu/libreadline.so.6 /lib/x86_64-linux-gnu/libreadline.so.6
COPY --from=extra /lib/x86_64-linux-gnu/libtinfo.so.5 /lib/x86_64-linux-gnu/libtinfo.so.5
COPY --from=extra /opt/mruby/bin /opt/mruby/bin
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 \
HOME=/root \
CONFIGURE_OPTS=--disable-install-doc \
LC_ALL=en_US.UTF-8
ENV PATH="/root/.rbenv/bin:/root/.rbenv/shims:${PATH}"

I need to know how to refactor the Dockerfile with Dotnet application

I need to refactor the Dockerfile of a Dotnet application which looks similar to the below.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["DockerExplained/DockerExplained.csproj", "DockerExplained/"]
RUN dotnet restore "DockerExplained/DockerExplained.csproj"
COPY . .
WORKDIR "/src/DockerExplained"
RUN dotnet build "DockerExplained.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "DockerExplained.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DockerExplained.dll"]
where as i need to use ubuntu20.04 as base image with image layers and i was told not to mention the busterslim. Can anyone guide how to proceed on this.
========================================
Here is the fresh requirement for the file... requirement is to install everything inside the raw image of Ubuntu 20.04 and i am not able to package the image layers start FROM ubuntu 20.04
I get seven different images but i need everything to run inside the ubuntu 20.04..
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["DockerExplained/DockerExplained.csproj", "DockerExplained/"]
RUN dotnet restore "DockerExplained/DockerExplained.csproj"
COPY . .
WORKDIR "/src/DockerExplained"
RUN dotnet publish "DockerExplained.csproj" -c Release -o /app/publish
FROM ubuntu:20.04
#Runtime-deps
FROM debian:buster-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
\
# .NET Core dependencies
libc6 \
libgcc1 \
libgssapi-krb5-2 \
libicu63 \
libssl1.1 \
libstdc++6 \
zlib1g \
&& rm -rf /var/lib/apt/lists/*
# Configure web servers to bind to port 80 when present
ENV ASPNETCORE_URLS=http://+:80 \
# Enable detection of running in a container
DOTNET_RUNNING_IN_CONTAINER=true
#Runtime
from mcr.microsoft.com/dotnet/core/runtime-deps:3.1-buster-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install .NET Core
RUN dotnet_version=3.1.3 \
&& curl -SL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Runtime/$dotnet_version/dotnet-runtime-$dotnet_version-linux-x64.tar.gz \
&& dotnet_sha512='e3f6f9b81bc3828b60f7da5a5c341373dc17f971f1de3f2714adcca180a630a60d4b681166fe78434d8b2ce023d2d08eff4f1935ec664130b7f856fa8e1cac2b' \
&& echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \
&& mkdir -p /usr/share/dotnet \
&& tar -ozxf dotnet.tar.gz -C /usr/share/dotnet \
&& rm dotnet.tar.gz \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
#ASPdotnet.3.1-busterslim
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim
# Install ASP.NET Core
RUN aspnetcore_version=3.1.3 \
&& curl -SL --output aspnetcore.tar.gz https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$aspnetcore_version/aspnetcore-runtime-$aspnetcore_version-linux-x64.tar.gz \
&& aspnetcore_sha512='ced0b7c9faaf250fbee2c850e8941d47a17da06fa8e576d57063fa4bbc6c8435de6ab488b683d4a692cd622e24d9592f11608a1b358074167cf0b76024815611' \
&& echo "$aspnetcore_sha512 aspnetcore.tar.gz" | sha512sum -c - \
&& tar -ozxf aspnetcore.tar.gz -C /usr/share/dotnet ./shared/Microsoft.AspNetCore.App \
&& rm aspnetcore.tar.gz
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "DockerExplained.dll"]``
The tag list for the aspnet images can be found here along with the OS versions in each image.
If you want to use Ubuntu 20.04, you need to change your base image to
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-focal AS base
If you want the default Debian 10, you can just remove the 'buster-slim' part of the image tag so you get
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
As you can see in the list, 3.1 and 3.1-buster-slim are the same image so if you use 3.1 you'll get the same image as you use now.
Edit: Dockerfile explanation, build / runtime
Here you create a temporary image called base which is based on the aspnet runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
Then you create a temporary image called build based on the SDK image where you build your solution. Note that this has nothing to do with the image above.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["DockerExplained/DockerExplained.csproj", "DockerExplained/"]
RUN dotnet restore "DockerExplained/DockerExplained.csproj"
COPY . .
WORKDIR "/src/DockerExplained"
RUN dotnet build "DockerExplained.csproj" -c Release -o /app/build
Then you create a new temporary image called publish based on the temporary build image
FROM build AS publish
RUN dotnet publish "DockerExplained.csproj" -c Release -o /app/publish
And finally you create the final image where you build upon your 'base' image from the top. Here you copy the published app from the 'publish' image.
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DockerExplained.dll"]
As you can see, the final image is made from the first 3 lines + the last 4 lines in your Dockerfile. The middle part is where you build your solution and those bits of the Dockerfile aren't included in the final image.
Here's how you could structure it in a more simple way with only 2 steps: build and runtime/final.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["DockerExplained/DockerExplained.csproj", "DockerExplained/"]
RUN dotnet restore "DockerExplained/DockerExplained.csproj"
COPY . .
WORKDIR "/src/DockerExplained"
RUN dotnet publish "DockerExplained.csproj" -c Release -o /app/publish
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS final
WORKDIR /app
EXPOSE 80
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "DockerExplained.dll"]

Receiving the dllNotFound error while executing the C# Solution in linux/mac/docker environment - kernel32.dll

Need to containerize the Solution Build on Microsoft Information Protection SDK 1.6 in linux Container Architecture. Always receiving common error of dllNotFound.
Error Received while executing MIP Initialization: MIP.Initialize(MipComponent.File);
Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory
at Microsoft.InformationProtection.Utils.UnsafeKernel32NativeMethods.LoadLibrary(String dllToLoad)
at Microsoft.InformationProtection.Utils.Loader.LoadDlls(String dllFolder, String dllName, String[] dllDependencies)
at Microsoft.InformationProtection.MIP.Initialize(MipComponent mipComponent, String path)
at MIPSolution.Program.Main(String[] args) in /src/Program.cs:line 55
Dockerfile to Execute the Application:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY ["MIPSolution.csproj", "./"]
RUN dotnet restore "MIPSolution.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "MIPSolution.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MIPSolution.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
# RUN dotnet --info
RUN echo "Build number: $buildno"
ENTRYPOINT ["dotnet", "MIPSolution.dll"]
All suggestions to make this application working will be very helpful.
Thanks

Unable to find view inside docker container

I'm using a containerized ASP.Net Core (2.1) app. The container is running Debian Stretch. Everything is working fine except this one small detail - whenever I want to use Rotativa I get this message:
Unable to find view '/app/wwwroot/templates/IssuedInvoice.cshtml'. The following locations were searched:\n/app/wwwroot/templates/IssuedInvoice.cshtml
That would very probably mean that file does not exist. Fair enough, I go into the docker container and issue cat /app/wwwroot/templates/IssuedInvoice.cshtml and what do I find? The file is listed without any errors.
Have anyone encountered such problem? I don't think that's a permission issue since the app runs inside the container as root anyway.
I have tested this outside of the container and everything works fine, same on Debug and Release configurations.
Dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["JTEPanel.Api/JTEPanel.Api.csproj", "JTEPanel.Api/"]
COPY ["JTEPanel.Infrastructure/JTEPanel.Infrastructure.csproj", "JTEPanel.Infrastructure/"]
COPY ["JTEPanel.SmsApi/JTEPanel.SmsApi.csproj", "JTEPanel.SmsApi/"]
COPY ["JTEPanel.Domain/JTEPanel.Domain.csproj", "JTEPanel.Domain/"]
COPY ["JTEPanel.Common/JTEPanel.Common.csproj", "JTEPanel.Common/"]
RUN dotnet restore "JTEPanel.Api/JTEPanel.Api.csproj"
COPY . .
WORKDIR "/src/JTEPanel.Api"
RUN dotnet build "JTEPanel.Api.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "JTEPanel.Api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
VOLUME /app/wwwroot
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales libgdiplus wkhtmltopdf
RUN ln -s /usr/bin/wkhtmltopdf /app/wwwroot/Rotativa/wkhtmltopdf
RUN sed -i -e 's/# pl_PL.UTF-8 UTF-8/pl_PL.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=pl_PL.UTF-8
ENV LANG pl_PL.UTF-8
ENTRYPOINT ["dotnet", "JTEPanel.Api.dll"]

Categories

Resources