Windows docker container vs Linux docker container - linux

I am new to the Docker/Kubernetes world in general.
As i am just starting with the whole architecture i have the following:
Azure Container Service -- up and running using Linux for master and agents
Docker for windows on my machine -- up and running
automated build for a .NetCore application on VSTS using Docker task to build and push the image to the Azure Container registry
Kubectl running as well kubernetes UI from master nodes
when building the .NetCore application from my machine using Docker commands and then publish it to the registry, Kubernetes is able to pull it and run it, but when the image is built and pushed by the VSTS build tasks kubernetes is failing to pull the images. after researching the error a bit, it turned out that the image coming from the VSTS build is made for windows and therefor cannot be pulled.
What is the difference between Docker Container for Windows and Linux, and how can we convert or specify the type while building the image.

What is the difference between Docker Container for Windows and Linux.
In short, Linux docker run on Linux and work with Linux kernel, Windows docker run on windows server 2016 or windows 10, work with windows hyper virtualization, and request windows dll and other packages.
So we can't run windows docker image on Linux docker.
how can we convert or specify the type while building the image.
As far as I know, we can't convert the docker image to another type.
We can use VSTS to build .NET core Linux Docker image, please refer to this blog.
Also, we can use different docker platform use Docker file to build docker image.
More information about how to build windows docker image with docker file, please refer to this blog.
More information about how to build Linux docker image with docker file, please refer to this article.
After docker image created, we can follow this article to push and pull an image from Azure container registry.

Related

Docker image with imported volume runs on Docker for mac, fails with "exec format error" not Docker CE on Linux

We're building an OS image using yocto on Debian which outputs a bzipped volume which we can use as a base image in docker using docker import and we push this image to our registry to use as a base image.
cp build/tmp/deploy/images/raspberrypi4/device.tar.bz2 .
docker import device.tar.bz2 registry/base_image
docker push registry/base_image
We include the base image as part of another docker image:
FROM registry/base_image
ADD target/app.jar app.jar
ADD docker-run.sh run.sh
ENTRYPOINT "./run.sh"
This image is then successfully built by our CI on a linux (Amazon Linux 2) agent, and pushed to the registry. I'm able to pull the image and run it on a Mac with the current version of Docker for Mac.
However, trying to run the same docker image on a linux machine (even on the same linux build agent) results in the following exec format error:
standard_init_linux.go:228: exec user process caused: exec format error
Using an alternative docker image as the base allows the entrypoint to execute, so I'm pretty sure the issue is related to our custom base image.
As docker is largely cross platform, I'm surprised it works on MacOS (intel and m1) but not Linux (tested in Ubuntu and Amazon Linux). I've tried both the Ubuntu and Docker hosted apt repositories for the docker install.
How can I further debug?
The issue here was that the base image was arm based, and that Docker for Mac can run arm images out of the box, even on intel machines.
https://docs.docker.com/desktop/multi-arch/
Docker Desktop provides binfmt_misc multi-architecture support, which means you can run containers for different Linux architectures such as arm, mips, ppc64le, and even s390x.
There's a good write up here for running arm docker images on linux x86 hosts
https://matchboxdorry.gitbooks.io/matchboxblog/content/blogs/build_and_run_arm_images.html
After installing QEMU on your host OS, you need to mount the QEMU binary:
docker run -it --name your-container-name -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static your-arm-image

Running an msi from Docker. Which host OS should choose

I want to create a docker container which installs an MSI application. I know i will be using the microsoft\widows\servercore image for this. Which host os i should use for this purpose. Will this image can be created and deployed in a Linux distribution??
If you're running a Windows container, you need to use Docker on Windows.
In general, containers can only run on the OS that they're designed for, but it is possible using Docker for Windows and Docker for Mac to run Linux containers since they provide a miniature Linux VM to run those containers. However, Docker on non-Windows OSes doesn't provide a copy of Windows to run containers with, so you have to use Windows to run Windows containers.
If you want your container to be deployable on a Linux host, it will need to be using a Linux container image.

Is it possible to build a Linux docker image on VSTS 2017 Hosted agent?

I've got a Dockerfile that pulls from a base image of microsoft/dotnet:2.0-runtime. When I do a build locally (on windows running Linux containers) I get a Linux docker image.
however, if we run the same build process on VSTS using a 2017 Hosted agent then we get a windows docker image.
Is it possible to build a Linux docker image on VSTS 2017 Hosted agent without having to use a Linux build agent?
No, there is no way to build a Linux docker image with VSTS Hosted VS2017 agent. Hosted VS2017 agent can only build for Windows docker images.
The workarounds to build Linux docker image as below:
Build with Hosted Linux Preview agent
Build with private agent with your own windows machine

Windows Container vs Docker Container and Azure Container Services/Kubernetes cluster with Linux OS

In the previous threads I asked a question about the way to move the Windows Containers into a Azure Container Services, and I received a great help
Deploying Windows Containers (created with Docker) into Azure Container Service
Pushing Windows Containers (built with Docker) into Azure Container Service (ACS) with Linus OS
I successfully created a Docker container on the Windows Server 2016 and through a Docker hub I moved the Docker container into a Kubernetes cluster with Windows Nodes where I was able to run these containers
However, after I ran a demo for my manager, I now need to conduct an additional research as my manager has some questions.
First of all, he is curious why the docker container cannot run on Windows (I do use Docker command when create the container) After all the Docker container should be platform independent and run in any environment, on both Windows and Linux
Also, I understand that there should be a switch between Windows and Linux when running Docker builds. However, on Windows Server 2016 with Containers there is no docker switch. Only command line is available.
Is that possible to switch between Linux and Windows modes on the command line and also, just in case, I am NOT working with Windows Containers, I am trying to work with Docker Containers.
Is that a true statement that a Docker Container with the .Net Core application (which is also cross platform cannot run on Linux)?
Thank you very much for your answer!
he is curious why the docker container cannot run on Windows (I do use
Docker command when create the container) After all the Docker
container should be platform independent and run in any environment,
on both Windows and Linux
To short, containers are not for virtualization, and they are using the resources of the host machine.
Windows container need .dll files, but Linux does not have those .dll files. And Linux based container need libraries, but windows does not have those.
Is that possible to switch between Linux and Windows modes on the
command line
About containers switch, please refer to this article. we can follow this article to configure docker for windows.
Is that a true statement that a Docker Container with the .Net Core
application?
As far as I know, for now, we can't run windows-based container on Linux.

linux machine using on docker for windows

I have windows server 2016 which has docker in built into it... so I am able to create windows image based containers and play around with them.
But now I want to create run linux based images, not able to do that... get below error
PS C:\Users\harishr> docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
image operating system "linux" cannot be used on this platform
I did installed docker-machine to create linux machine, but not getting command line options to do that

Resources