How to install Docker Desktop inside a Windows Server Core based container - windows-container

Haven't come across any article that says how to setup Docker in Docker for Windows (native, not WSL). Trying to build a Windows Server Core based image but from within a Windows Server Core Container. Is this possible?

So, I took some time to test this out and it turns out that it actually works:
Windows container running inside a Windows container
The catch here is that the docker engine on the container needs to be mapped to the docker engine from the underlying container.
Here is the docker file I used:
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2022
RUN powershell -Command `
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
Invoke-WebRequest `
-Uri https://download.docker.com/win/static/stable/x86_64/docker-20.10.15.zip `
-OutFile docker.zip; `
Expand-Archive docker.zip -DestinationPath 'C:\Program Files'; `
Remove-Item docker.zip -Force `
&& setx /M PATH "%PATH%;C:\Program Files\docker"
Here are the commands I ran:
docker run -i -v \\.\pipe\docker_engine:\\.\pipe\docker_engine inception:v1 powershell
This will open a container interactively. From there, run:
docker run --rm mcr.microsoft.com/windows/servercore:ltsc2022 cmd /c hostname

Docker Desktop should be used on Windows 10/11 only. For Server environments, which Windows containers are based on, you should install the Docker/Mirantis engine. However, I'm not entirely sure this would work and even if it does (one can try), it should not be supported.

Related

Docker on Windows Server not stable

I'm using Docker Desktop on Windows 10 with Windows containers without any problems.
Now, I also want to use Docker on Windows Server, I've tried Windows Server 2016 and Windows Server 2019 so far.
I can install Docker Enterprise without any problems, I can start a container based on the nanoserver image without problems. But after a while (something between 10 and 20 minutes), the container terminates.
Has anyone seen such a behavior? Is this the expected behavior?
The Windows is
OS Name: Microsoft Windows Server 2019 Standard
OS Version: 10.0.17763 N/A Build 17763
I've installed Docker with this commands:
Install-WindowsFeature -Name Containers
Uninstall-WindowsFeature Windows-Defender
Restart-Computer -Force
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider -Force -RequiredVersion 19.03
Start-Service docker
Afterwards I can use the docker ps command and I can start the nanoserver image using the command
docker run -it mcr.microsoft.com/windows/nanoserver:1809 cmd
The container starts and I can use it.
But when I leave it open and do nothing within, after a while it terminated.
The same happens with the image servercore:ltsc2019 and images derived from that one.

docker run command to install azure cli on windows container

I am trying to build a windows container with azure cli installed on it. below is my try. I am getting support from internet for linux but not for windows.
I am exactly looking for the code to create a windows container, install azure cli and install kubectl and upload powershell file and execute it at the starting of container and close the container after finishing.
FROM mcr.microsoft.com/windows/servercore:1903
RUN -it mcr.microsoft.com/azure-cli:2.9.1
WORKDIR /K8sDeploy
COPY deployk8s.ps1 .
ENV Storage_Account_Name=""
ENV Storage_Account_Key=""
ENV Storage_Account_Container=""
ENV PS_File=""
ENV Storage_Account_Subscription=""
ENTRYPOINT ["powershell.exe", "-executionpolicy" , "Bypass" ,
"C:\\K8sDeploy\\deployk8s.ps1","$Env:Storage_Account_Name" ,"$Env:Storage_Account_Key","$Env:ENV
Storage_Account_Container=","$Env:PS_File","$Env:Storage_Account_Subscription"]
this powershell file containers az commands and kubectl commands.
I know that RUN -it mcr.microsoft.com/azure-cli:2.9.1 wont work but what is the windows version of this and if I am totally wrong.. please correct me.

running local webpage using a docker IIS container

Running Docker for windows to host a local IIS to test a webpage, using the default windows IIS dockerpage
I am not sure what part to change in my dockerfile that allows me to run my webpage. Simply editing the COPY command in the dockerfile is what I thought I would need to change, but that isnt the case. What do I need to do to have it run a different html file instead of the default windows IIS page?
EDIT : Was able to find the open container by searching wwwroot in my C:, and I copy and pasted my hello world index.html page and was able to get it running
You could follow below steps:
Create a Dockerfile with your website
FROM mcr.microsoft.com/windows/servercore/iis
RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*
WORKDIR /inetpub/wwwroot
COPY content/ .
You can then build and run the Docker image:
$ docker build -t iis-site .
$ docker run -d -p 8000:80 --name my-running-site iis-site
There is no need to specify an ENTRYPOINT in your Dockerfile since the microsoft/iis base image already includes an entrypoint application that monitors the status of the IIS World Wide Web Publishing Service (W3SVC).
With the current release, you can't use http://localhost to browse your site from the container host. This is because of a known behavior in WinNAT, and will be resolved in future. Until that is addressed, you need to use the IP address of the container.
Once the container starts, you'll need to finds its IP address so that you can connect to your running container from a browser. You use the docker inspect command to do that:
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" my-running-site
You will see an output similar to this:
172.28.103.186
You can connect the running container using the IP address and configured port, http://172.28.103.186:8000 in the example shown.
In addition to static content, IIS can run other workloads including but not limited to ASP.NET, ASP.NET Core, NodeJS, PHP, and Apache Tomcat.
For more detail you could refer below links:
https://learn.microsoft.com/en-us/aspnet/mvc/overview/deployment/docker-aspnetmvc
https://mcpmag.com/articles/2019/11/20/iis-on-windows-server-containers.aspx
Cannot access an IIS container from browser - Docker
I have changed the docker file like below after which it worked perfectly
FROM mcr.microsoft.com/windows/servercore/iis
RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*
WORKDIR /inetpub/wwwroot
RUN mkdir -p content
COPY . content/

Cannot access an IIS container from browser - Docker

Windows Version: Windows Server 2016
Docker for Windows Version: 18.09.0
I try to follow the steps in https://learn.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-images
I have a Docker file on c:\Build:
FROM microsoft/iis
RUN echo "Hello World - Dockerfile" > c:\inetpub\wwwroot\index.html
Please note that I have tried using FROM microsoft/iis:10.0.14393.206 as well
So, I ran using powershell with admin privilege:
docker build -t imagename c:\Build
Then I ran:
docker run -d -p 8000:80 --name container imagename ping -t localhost
All of the above steps are fine, but I cannot access the website,
I tried every combination like:
the ip address from ipconfig:8000 or 80; the ip address from inspect :8000 / 80.
Please note that I had also set up Firewall to allow port 8000 as well
But it all failed.
Then, I went to the Internet and found that I can actucally call the bash. therefore, I ran exec, however, there was something strange happened:
I am not sure whether it means the container is not worknig?
But the inspect and container ls show it should be working.
fyi
network:
inspect container:
I really cannot find any solution from the Internet
Any advice would be helpful, thanks
UPDATE: I got it to work with the following configuration below, and with remote IIS access. Make sure that firewall is not blocking docker to your local ip's. Also, the app in our case is part of a website, so we need to use Webadministration to deploy it as an application to make it work. Logs and everything else is working now and we have a running sample.
I been playing as well with the docker container and I been having similar issues deploying. I am using a server core image instead as it has full fledge powershell on it, but I have my dockerfile defined like this to build the image at the moment doing tests because the application seems to not start. the app is not on core yet but will migrate to it soon to make the working image smaller. Another thing to note from this sample, the application pool is not getting created even tho its being defined on my commands. With this you can connect remotely with the iis remote management tool and check how is the server setup up to this point inside the docker.:
##Pull the base image to use
FROM mcr.microsoft.com/windows/servercore/iis
#Enable verbose output in case of errors
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
#install all needed features of IIS
RUN Install-WindowsFeature -name Web-Server -IncludeManagementTools ;\
Install-WindowsFeature -name Web-Basic-Auth ;\
Install-WindowsFeature -name Web-Windows-Auth ;\
Install-WindowsFeature -name Web-Net-Ext45 ;\
Install-WindowsFeature -name Web-ISAPI-Ext ;\
Install-WindowsFeature -name Web-ISAPI-Filter ;\
Install-WindowsFeature -name Web-WHC ;\
Install-WindowsFeature NET-Framework-45-ASPNET ; \
Install-WindowsFeature Web-Asp-Net45 ;\
Install-WindowsFeature -Name Web-Mgmt-Service ;\
Install-WindowsFeature -name Web-Mgmt-Tools ;\
Install-WindowsFeature -name Web-Mgmt-Compat ;\
Install-WindowsFeature -name Web-Scripting-Tools ;\
Dism /online /enable-feature /featurename:IIS-ManagementService /all ;\
##Still inside the same run command, enable remote management for IIS on docker
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force ;\
Get-Service -Name WMSVC | Start-Service ;\
Set-Service –Name WMSVC –StartupType 'Automatic' ;\
##In the same run Command add the user and password for IIS remote management
net user myuser superP#ss123 /ADD ;\
net localgroup administrators myuser /add
COPY . myapp
RUN New-WebAppPool myapp
#The configStore is an application of a website, so add it as such to the service
RUN Import-Module WebAdministration; Get-Module ;\
New-Item 'IIS:Sites\Default Web Site\myapp' -physicalPath 'c:\myapp' -ApplicationPool 'myapp' -type 'Application'
EXPOSE 51329 80
The other question I have no answer is if we can actually assign a memory size to the docker images on creation and not just the standard by the owner.
After a month, I have another way to get to the container's IIS...
I am going to post the answer here, in case someone encounters similar issues
The setup greatly relates to https://blogs.msdn.microsoft.com/containerstuff/2017/02/14/manage-iis-on-a-container-with-the-iis-admin-console/
The difference is:
To fully install IIS in a container, use the following DockerFile:
(There are some steps missed in the document, you cannot have wmsvc and IIS admin services installed without the following lines included in the Dockerfile below)
FROM microsoft/dotnet-framework:4.6.2
RUN powershell -Command Install-WindowsFeature -name Web-Server -IncludeManagementTools
RUN powershell -Command Add-WindowsFeature web-webserver
RUN powershell -Command Install-WindowsFeature -name Web-Basic-Auth
RUN powershell -Command Install-WindowsFeature -name Web-Windows-Auth
RUN powershell -Command Install-WindowsFeature -name Web-Net-Ext45
RUN powershell -Command Install-WindowsFeature -name Web-Asp-Net45
RUN powershell -Command Install-WindowsFeature -name Web-ISAPI-Ext
RUN powershell -Command Install-WindowsFeature -name Web-ISAPI-Filter
RUN powershell -Command Install-WindowsFeature -name Web-WHC
RUN powershell -Command Install-WindowsFeature -name Web-Mgmt-Tools
RUN powershell -Command Install-WindowsFeature -name Web-Mgmt-Compat
RUN powershell -Command Install-WindowsFeature -name Web-Mgmt-Service
RUN powershell -Command Install-WindowsFeature -name Web-Scripting-Tools
RUN powershell Dism /online /enable-feature /featurename:IIS-ManagementService /all
Docker run the image with -it / Docker attach the container
start container's powershell by typing powershell
running Get-service to see if IISadmin, w3svc and wmsvc are there.
It will show that wmsvc is not started (strangely, even I run sc config wmsvc start=auto in DockerFile still does not work)
net start the service
use host's IIS to connect to the container's IIS (similar to the step given by the link above)
It should be able to connect to the container from host and now you have successfully implemented a web application in a container.
PS. Note that firewall may block the remote management process

Using absolute path with docker run command not working

What's the difference between these two docker run commands and why one is working and the other does not.
Working Command
docker run --publish=7474:7474 --volume=$HOME/neo4j_test/data:/data neo4j
Not Working
docker run --publish=7474:7474 --volume=C:/Users/USERNAME/neo4j_test/data:/data neoj
docker run --publish=7474:7474 --volume=C:\Users\USERNAME\neo4j_test\data:/data neo4j
Error for these commands
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Invalid bind mount spec "C:UsersUSERNAMEneo4j_testdata:/data": invalid mode: /data.
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.
In the non-working commands, I just replaced $HOME with the absolute path for my user profile folder C:/Users/USERNAME
UPDATE
I did inspect the value for $HOME by executing echo $HOME on Windows Powershell. And it is in fact C:\Users\USERNAME. I also did look at the link that #Titouan Freville has commented. So I used the command
docker run --publish=7474:7474 --volume=/c/Users/USERNAME/neo4j_test/data:/data neo4j
isntead of
docker run --publish=7474:7474 --volume=C:/Users/USERNAME/neo4j_test/data:/data neoj
and it is working now. Right now I'm just wondering where the transformation of $HOME from C:\Users\USERNAME to /c/Users/USERNAME happens
For anyone still having this problem with Docker-for-Windows, here are the 2 solutions that work:
Prefix your command
with MSYS_NO_PATHCONV=1
In full: MSYS_NO_PATHCONV=1 docker run -v /c/path:/path
Use double-slashes
// at the beginning
In full: docker run -v //c/path:/path
Source: https://github.com/moby/moby/issues/24029#issuecomment-250412919
To close the subject. Here is the solution ;) docker toolbox mount file on windows
Also, the interpolation of $HOME by docker on windows have to be compatible with it, so it should transform it by himself when you call it in docker command.

Resources