📜 ⬆️ ⬇️

Windocks - SQL Server and .NET containers on Windows Server 2012 R2 with docker api support



Hello, dear readers of Habr. Today we will talk about Windocks, a product of the company of the same name, positioning itself as the first docker engine for Windows. While Microsoft clients are expecting a new version of Windows Server, namely Windows Server 2016 (at the time of writing, Technical Preview 5 is available ) with native support for docker containers , the creators of windocks tried to provide docker containers for the current generation of windows server systems.

So, what is Windocks? In short, this is a mixture of a ported version of an existing daemon docker and an open source container project from Uhuru Software . About the features of Windocks and the challenges that faced the developers, you can read here .
')
As part of this material, we will try to figure out how working with windocks is fundamentally different from working with the original daemon for linux , what are the limitations of the current version of windocks and whether to embed the tool in its development and testing processes.

What is available now


At the time of this writing, windocks supports the following operating systems:


In these OSs you can create containers from images:


Deploy windocks to VPS with Windows Server 2012


More recently, Windocks announced the release of the community edition, in order to be able to get acquainted with the product features for free. This version we will deploy. We send a request through the form on the site . The answer comes instantly, and in a minute the link is already with us.

We will use VPS with 2x2.6GHz configuration, 2GB RAM, 20GB HDD / Windows Server 2012 R2 as the environment for deployment of windocks. In order to use SQL Server containers on a VPS, you must install SQL Server. Install and then install the windocks itself. No additional settings are required during the installation process.

Generate certificates and keys for the host and for the client to configure two-way authentication and provide them with windocks:
server-key.pem -> C:\Users\Administrator\.docker\key.pem server-cert.pem -> C:\Users\Administrator\.docker\cert.pem ca.pem -> C:\Users\Administrator\.docker\ca.pem 


Now run the windocks (the launch command looks a little different than for the Linux docker daemon):
 docker -H tcp://WINDOCKS_IP:2376 -dD --tlsverify=true 


In the launch logs see:
 time="2016-06-30T14:32:06.901345300+03:00" level=info msg="Daemon has completed initialization" 

Do not forget to allow incoming connections to tcp port 2376 in the firewall for the desired ip-addresses.

Connect using standard docker client


As you probably guessed from the title, Windocks supports docker RESTful api . This means that you can use the standard console client docker to work with it. However, windocks currently do not support all commands, but only part of them. DockerFile also supports a limited set of commands (FROM, ADD, COPY, ADDDB, MOUNTDB). A complete list of commands for comparison can be found here .

We connect to the windocks absolutely as well as to the usual docker host (we recommend creating aliases commands for working with the client, in windows you can do this, for example, using DOSKEY):
 docker.exe --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem -H=WINDOCKS_IP:2376 version 


As a result, we get something like:
 Client version: 1.7.0 Client API version: 1.19 Go version (client): go1.4.2 Git commit (client): 0baf609 OS/Arch (client): windows/amd64 Server version: $VERSION Server API version: 1.19 Go version (server): go1.5.1 Git commit (server): $GITCOMMIT OS/Arch (server): windows/amd64 


Run the .NET application in windocks


Windocks has its own local registry of images, which in the community addition contains 2 images by default: dotnet and mssql. Its contents can be obtained by running (we believe that we have already done an alias with the parameters for authentication using certificates):
 docker images 


Result:


So, 2 basic images are available to us: dotnet-4.5 and mssql-2014. Together with Windocks there is a set of samples that demonstrate its capabilities.

As part of this article, we will look at testMountDb and testDotnet samples. The first mounts into a container created on the basis of the mssql-2014 image, the base for the test application. The second is using this database to work in another container. Copy them to the client OS to work directly with a standard client.

Collect the container from the sample testMountDb and run it.
 docker build testMountDb 


We get the following:
 Sending build context to Docker daemon 2.048 kB Sending build context to Docker daemon Step 0 : FROM mssql-2014 Step 1 : MOUNTDB customers C:\dcr\mountDbExample\customerdata.mdf ContainerId = c4d6e4f7bdc9cfc4c8b62b09572b255f43b56716d862b28e291e7af86e08bc3f & ContainerPort = 10001 & ContainerUserName = prison_oo_aqRdapH & ContainerPassword = Pr!5n5A39SvNRo & MSSQLPort = 10001 & MSSQLServerUserName = sa & MSSQLServer SaPassword = Pr!54q0flmqoM1 & DockerFile output: & Line 2- Mounted DB: customers, C:\ dcr \mountDbExample\customerdata.mdf 


From here we will need MSSQLServerUserName and SaPassword, which we will use in web.cfg in the connection string.
Run the created container:
 docker start c4d 


Now we will assemble the container from the testDotnet sample and run (all the same):
 docker build testDotnet 


Result:
 SECURITY WARNING: You are building a Docker image from Windows against a Linux Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories. Sending build context to Docker daemon 20.99 kB Sending build context to Docker daemon Step 0 : FROM dotnet-4.5 Step 1 : COPY web.config app-root\\runtime\\repo Step 2 : COPY default.aspx app-root\\runtime\\repo Step 3 : COPY default.aspx.cs app-root\\runtime\\repo Step 4 : COPY main.css app-root\\runtime\\repo Step 5 : COPY windockslogo.png app-root\\runtime\\repo Step 6 : COPY testrun.bat . Step 7 : RUN cmd.exe /C .\testrun.bat ContainerId = 3b8cefeef04d3ac5010fa8e37b04ce42aa207359e4848581222d521839ea7a04 & ContainerPort = 10003 & ContainerUserName = prison_oo_P4yo5gA & ContainerPassword = Pr!5c6g8mVfQq7 & DOTNETPort = 10003 & DockerFile output: PS docker start 3b8 


Open in browser
 http://WINDOCKS_IP:10003 
and, if done correctly, we see the following:


Now save the application image in the windocks registry by doing the following:
 docker commit a29 windocks_dotnet_demo_v1 


And display an updated list of images:
 docker images 




Now other users can use the windocks_dotnet_demo_v1 image.

findings


In our opinion, despite the fact that windocks is quite limited (what we have mentioned at the very beginning of the article) is a tool compared to a docker for Linux, it copes well with its standard tasks for providing SQL Server and .NET containers. It can also be quite comfortable to use for developing and testing applications on ASP.NET 4.5 / MSSQL in small teams, however, for use in production, the tool is still too young and may still become irrelevant after the release of Windows Server 2016. What do you think, dear readers?

Source: https://habr.com/ru/post/304508/


All Articles