Mixing linux and windows

Mixing Windows and Linux containers with Docker Compose

Premier Developer Consultant Randy Patterson explores how to mix Windows and Linux containers with Docker Compose. Running Linux containers on a Windows host has been available for awhile now. However, getting Windows and Linux containers to communicate without Docker Compose results in using the containers’ IP Addresses. This is not a good solution since container IP Addresses change often. A better solution is to take advantage of the Docker Compose networking and use the service name instead of the IP address. A Windows host has no problem running Linux containers but Docker Compose does not automatically support multi-platform hosts. The platform configuration option was added to Docker Compose files starting with version 2.4 and then removed beginning with version 3.x. It is a know bug and the expectation is that the platform option will return soon. When this article was written, it has not yet appeared in version 3.x so we will continue to use file format version 2.4 for our Docker Compose yaml files.

Setting up your environment

Running Linux containers on Windows and platform support in Docker Compose requires Windows 1803 or greater. I am running Windows 10 1809. In addition, you must be running the latest version of Docker for Windows and have the experimental features enabled. C:\Users\ranpat\AppData\Local\Temp\SNAGHTML9efec91.PNGIf you are running different versions of Windows or Docker your mileage may vary.

Source Code

  1. Webtier.sln – Asp.Net MVC application running .NET Framework 4.6.x and a Dockerfile for creating a Windows image hosting IIS.
  2. ApiTier.sln – Asp.Net Core 2.1 application and a Dockerfile for creating a Linux image to host the application

The application is a simple web page that displays the hostname of the Web Tier then calls the API Tier to get and display the API hostname. When running in containers, the container Id is displayed. Your Id’s will be different

Читайте также:  Home Page

Docker-Compose

The docker-compose.yml file, located in the root of the solution, adds the platform: windows parameter to the webtier service and the platform: linux parameter to the apitier service.

version: '2.4' services: webtier: image: webtier:win platform: windows ports: - 80 build: context: .\WebTier dockerfile: Dockerfile depends_on: - apitier environment: ApiHost: "apitier" apitier: image: apitier:linux platform: linux expose: - 80 build: context: .\ApiTier dockerfile: Dockerfile

Next, bring up the multi-container, multi-platform application using docker-compose. Start a powershell prompt in the solutions root folder, the same folder that contains the docker-compose.yml file. Type the command:

Docker Compose will create the images if they do not already exist, then create the virtual network to host the containers and finally start the containers in the correct order.

C:\Users\ranpat\AppData\Local\Temp\SNAGHTML9a0e9f1.PNG

Finally, retrieve the host port of the webtier container

Use your browser to navigate to http://localhost:38736 (your port number will be different)

If the Windows Web Tier was able to communicate with the Linux API Tier, you will see the id for each of the containers (your id’s will be different) on the web page.

Using the platform option in your configuration files allows Docker Compose to mix Windows and Linux containers when hosted on a multi-platform host like Windows. Keep in mind that this is an experimental feature and is not yet ready for production environments.

Developer Support App Dev Customer Success Account Manager, Microsoft Developer Support

Anyone who has ever passed at least one of the Microsoft certification exams has a Microsoft Certified Professional (MCP) profile created with an ID (MCID) generated. This profile is now part of the Microsoft Learning platform that allows a person to track all activities related to certification accomplishments, both active and past.

Читайте также:  Linux узнать порт устройства

On this episode of the On.NET Show, ADM Isaac Levin talks about how we can better triage issues in Production environments using Azure Monitor, Application Insights, Snapshot Debugger, SnapPoints and LogPoints.

3 comments

Hi,
a very nice article.
I am using LCOW for several months and it works for integration tests ina mixed environment very well.But now I have a problem using microsoft/dotnet:2.2-aspnetcore-runtime(or …-alpine) for the linux images.
Building the docker image on linux with this base image and running it in anLCOW environment works in that way that the container starts and itsfunctions are available.
But if I want to stop the container it takes several minutes to stop thecontainer.
Do you have any idea why it takes so long?
Best regardsChristian

Randy Patterson —> Randy Patterson April 1, 2019 6:30 am

Thanks for the comment Christian. LCOW containers taking a long time to stop is a known issue that hasn’t been fixed yet. I don’t always experience it with ‘docker stop’ but I do with ‘docker-compose down’. Just be patient for now and don’t kill the process. ‘docker-compose down’ will also remove the network it created and if that gets interupted it can be difficult to fix.

Источник

Running Docker Windows and Linux Containers Simultaneously

Many of you with familiarity with Docker for Windows know how you currently have to switch between running either Windows or Linux Containers. In the following post, Premier Developer Consultant Randy Patterson teaches us how to combat this limitation and run Docker Windows and Linux Containers simultaneously on the same host. Starting with Docker for Windows version 18.03.0-ce-win59 the Linux Containers on Windows (LCOW) is available as an experimental feature. Previously, you could get LCOW only on the Edge or Nightly Build Channels. For people like me who need a stable version of Docker for Windows, this feature was not available until now. Docker for Windows currently allows you to switch between running Windows or Linux Containers but not both. Linux containers were hosted in a Linux Virtual Machine making it convenient for testing purposes but not production. LCOW will make it possible to have an application that mixes Linux and Windows containers together on a single host.

Читайте также:  Complete linux commands pdf

What you Need

In order to use the new LCOW feature, you will need the latest version Docker for Windows and have the Experimental Features enabled: 1. Docker for Windows version 18.03.0-ce-win59 or greater image 2. Experimental Features enabled a. Docker -> Settings –> Daemon clip_image004

Let’s Get Started

With Docker for Windows started and Windows containers selected, you can now run either Windows or Linux Containers simultaneously. The new –platform=linux command line switch is used to pull or start Linux images on Windows.

docker pull --platform=linux ubuntu

image

Now start the Linux container and a Windows Server Core container.

docker run --platform=linux -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done" docker run -d microsoft/windowsservercore ping -t 127.0.0.1

image

Both containers are running on a single host. If you list your local image cache you’ll see a mixture of both Windows and Linux images. To determine the operating system an image requires you can use docker inspect and filter on the “Os” property.

docker inspect --format '>' ubuntu

image

Conclusion

Running Windows and Linux containers simultaneously on the same host is an interesting new feature in Docker with lots of possibilities. However, this is an experimental feature and may have some issues. One known problem is volumes are not stable especially when mapping between Linux and Windows file systems. This can cause some containers that rely heavily on volumes to fail to load. Furthermore, tooling support is not yet complete. For example, Docker-Compose and Kubernetes cannot yet mix Windows and Linux containers. Microsoft is currently tracking issues here and feature progress can be tracked at the Github site here.

Источник

Оцените статью
Adblock
detector