I am a newbie to docker. How can we find which .net framework is installed in a docker image? - docker

I have copied .NET framework from my local directory and build an image by using the below Dockerfile
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
ADD setup C:\setup
RUN cmd.exe /c start /wait C:\setup\NDP471DevPack.exe /q
RUN powershell -Command rm C:\setup -r -Force
WORKDIR C:\\Project
ENTRYPOINT ["C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe"]
Now I want verify that the .NET framework is whether installed or not in the image that was build?

You can run dotnet --version to see if there's a .NET runtime installed and which version it is. Something like this
docker run --rm --entrypoint=dotnet <image name> --version

You should be able to use:
reg query "HKLM\SOFTWARE\Microsoft\Net Framework Setup\NDP" /s
In Visual Studio I can select my container and click "Open Terminal Window" and paste the above command.

Related

How can I run `powershell` command on mcr.microsoft.com/powershell container

My docker image is from mcr.microsoft.com/powershell:latest which has powershell installed. Why do I get this error when build docker image: /bin/sh: 1: Install-Module: not found
Below is my dockerfile:
FROM mcr.microsoft.com/powershell:latest
RUN Install-Module dbatools -Force
I can run the command Install-Module dbatools -Force when I manually launch a container from mcr.microsoft.com/powershell:latest. Why can't I run it from building the image? Does it have a different context? If it uses my localhost context, does it mean I need to install powershell on my Mac OS?
If I want to run a powershell script as ENTRYPOINT, how can I specify it?
you can use SHELL directive in Dockerfile:
escape=`
SHELL ["powershell","-command"]
RUN New-Item -ItemType Directory C:\Example
see more here

Docker image dotnet-framework 4.7.2-sdk missing SDK files

I am seeing weird behavior with docker build image outputs.
When I build a docker image from my dockerfile on Windows 2016 server machine (M1), the output image is fine and as expected. However, if I try the same procedure on a different machine (M2), some crucial files are missing. I don't see any errors of any sort when building images. Both M1 and M2 are same Win2016 Datacenter OS. M2 is domain joined but M1 is not.
My dockerfile is like this:
# escape=`
FROM microsoft/dotnet-framework:4.7.2-sdk
RUN mkdir c:\install
ADD WebDeploy_amd64_en-US.msi c:\install\WebDeploy_amd64_en-US.msi
WORKDIR c:\install
RUN powershell start-Process msiexec.exe -ArgumentList "/i","c:\install\WebDeploy_amd64_en-US.msi","/qn" -Wait
ADD https://aka.ms/vs/15/release/vs_buildtools.exe C:\install\vs_buildtools.exe
SHELL ["cmd", "/S", "/C"]
RUN C:\install\vs_buildtools.exe --quiet --wait --norestart --nocache `
--installPath C:\BuildTools `
--add Microsoft.Net.Component.4.7.1.SDK `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
RUN mkdir c:\install\sxs
ADD microsoft-windows-netfx3-ondemand-package.cab c:\install\sxs\microsoft-windows-netfx3-ondemand-package.cab
WORKDIR c:\install
RUN powershell Install-WindowsFeature -Name NET-Framework-Features -Source C:\install\sxs -Verbose
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
Contents of C:\Program Files (x86) from container running on M2:
Common Files
IIS
internet explorer
Microsoft Visual Studio
Microsoft.NET
MSBuild
Reference Assemblies
Windows Defender
WindowsPowerShell
Contents of C:\Program Files (x86) from container running on M1:
Common Files
IIS
internet explorer
Microsoft SDKs
Microsoft Visual Studio
Microsoft.NET
MSBuild
Reference Assemblies
Windows Defender
Windows Kits
WindowsPowerShell
Same command used to build images on M1 and M2:
docker build -t vsbuildtools -m 2GB .
What am I missing here?

Docker for Windows exits with code 127 when building image

When I try to build this Docker-Image, I get the following error:
FROM java:8
WORKDIR /app
ADD . /app
EXPOSE 8080
RUN ./gradlew build
CMD ./gradlew bootRun
When I just build the app with "gradlew build" it runs and when I try to run this Docker Image with a Mac, it works too, just not for windows
EDIT:
This is not a great answer, but what I found is that when Windows mounts files into Docker from Windows, it leaves Windows-like line endings on the mounted files. A janky way to solve it in your Dockerfile would be to install dos2unix in the container and add a
RUN dos2unix gradlew
prior to executing your build process. Unfortunately, this is a TERRIBLE solution. Hopefully Docker for Windows on WSL2 that is supposed to release soon will solve this better but for now you are stuck with this janky solution.
gradlew must be marked as executable.
chmod +x gradlew
Mac and Linux share permissions scheme but Windows needs to use a virtual FS so it copies files with default permissions - 644 and you need 755.

How to remove a virtualenv created by "pipenv run"

I am learning Python virtual environment. In one of my small projects I ran
pipenv run python myproject.py
and it created a virtualenv for me in C:\Users\USERNAME\.virtualenvs
I found it also created or modified some files under my project source code directory. I am just wondering how to cleanly delete this virtualenv and reverse my project back to a no-virtualenv state.
I am using python 3.6.4, and PyCharm.
You can run the pipenv command with the --rm option as in:
pipenv --rm
This will remove the virtualenv created for you under ~/.virtualenvs
See https://pipenv.kennethreitz.org/en/latest/cli/#cmdoption-pipenv-rm
I know that question is a bit old but
In root of project where Pipfile is located you could run
pipenv --venv
which returns
Linux/OS X:
/Users/your_user_name/.local/share/virtualenvs/model-N-S4uBGU
Windows:
C:\Users\your_user_name\.virtualenvs\model-N-S4uBGU
and then remove this env by typing
Bash/Zsh:
rm -rf /Users/your_user_name/.local/share/virtualenvs/model-N-S4uBGU
Powershell:
Remove-Item -Recurse -Force 'C:\Users\your_user_name\.virtualenvs\model-N-S4uBGU'
Command Prompt
rmdir /s "C:\Users\your_user_name\.virtualenvs\model-N-S4uBGU"

Dotnet Antiforgery dll is missing in docker container in OSX

I have this idea of having a docker container mount a folder where there is an already compiled Aspnet core 1.1 application.
When I do that a file is missing. What is the best way to make it... not missing?
How to recreate problem:
In my OSX host I create a folder /myrootedpath/TheApp and
dotnet new -t web
dotnet restore
dotnet run
to create and start my hello world web app.
(I can curl localhost so I know it works in the host.)
I stop the server with ctrl-c.
I then create a container which mounts the folder mentioned, compiles and starts the web server through
docker run -p 80:80 -ti \
-v /myrootedpath/TheApp:/theapp microsoft/dotnet \
/bin/bash -c 'cd /theapp; dotnet run'
but it stops with a
Project theapp (.NETCoreApp,Version=v1.1) was previously compiled. Skipping compilation.
Error: assembly specified in the dependencies manifest was not found — package: ‘Microsoft.AspNetCore.Antiforgery’, version: ‘1.0.1’, path: ‘lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll’
I see Antiforgery.dll is missing.
I guess I can find it and copy it and create a new image.
Is that a recommended solution?
UPDATE
As I start a bounty I want to clarify that the question boils down to what is is needed to execute dotnet core code compiled outside the container.
When I run dotnet restore (on my Win machine) I see that packages are downloaded/copied not to project folder, but to <userhome>/.nuget/packages/.
So, your docker image still have no packages you downloaded to your host via dotnet restore (because dotnet run only compiles app itself, without copying dependencies).
You should:
use dotnet publish to create "ready-to-run" distrib, and run it in container;
or, run dotnet restore inside docker image at least once when you change dependencies (every time);
or, map packages folder from your host system into docker.

Resources