Home
Clone this wiki locally
#Overview This document is prepared while learning docker containers.
- What is current problem we have with software deployment?
- What is container?
- Demo app - ASP.NET web app Authenticating with custom OAuth Server (Node.js)
- [Source] (https://github.com/sairamaj/docker)
Software Development
Reference Assemblies(Applicable to .NET developers)
3-4 years back
- Needed foo.dll
- Download from source
- Unzip it
- Check in common directory (like toolset)
- Check this source
- Reference this assembly in source
- Build server uses this checked dll during compilation
Current
- Reference from nuget server
- Update the package.json
- Check in the package.json
- Foo.dll was is not checked in source
- Needed different version in different project , reference new version from nuget
- Thing become easy ,right?
Software Deployment
Current
- Download setup.exe ( .msi/zip )
- Run setup.exe to install
- Run the installed software
- Needed new version? * Uninstall existing version * Do the above steps for new version * Run new versioned software
- Needed old version again for some reason(say for testing in old) * Uninstall existing * Install old and use it
- Needed new again?
- repeat
##Future? Lets revisit this after going through the container technology
#What is Container?
- Containers are a solution to the problem of how to get software to run reliably when moved from one computing environment to another
- This could be from a developer's laptop to a test environment, from a staging environment into production and perhaps from a physical machine in a data center to a virtual machine in a private or public cloud
- Consists of an entire run time environment: an application, plus all its dependencies, libraries and other binaries, and configuration files needed to run it, bundled into one package
Is it Virtual Machine?
In way it is with certain differences. ###virtualization technology
- the package that can be passed around is a virtual machine and it includes an entire operating system as well as the application
- A physical server running three virtual machines would have a hyper visor and three separate operating systems running on top of it.
- may take several minutes to boot up their operating systems and begin running the applications they host
###containerized applications
- runs a single operating system, and each container shares the operating system kernel with the other containers
- containers are much more lightweight and use far fewer resources than virtual machines
- containerized applications can be started almost instantly
#What is Docker?
- Docker has become synonymous with container technology because it has been the most successful at popularizing it
- Set of tools
#Sample Application In order to demonstrate the container features I took a sample application and containerize them in both Windows and Linux OS.

Web Application
- Uses ASP.NET core
- Uses Windows Nanoserver with dotnet installed image.
- Customize middle ware to communicate to custom OAuth server to authenticate the user Note: Not finished just to show a communication between one container app to another container
- Source
OAuth server
- Dummy OAuth server (implements Authorizaton flow uses in web apps)
- Uses Node.JS
- Uses windows server image
- Source
###Here are the steps for walk thru
- Lets build one container manually
- Verify that application is working.
- Lets automate the 2nd container build
- Lets build multiple containers as single application
- Lets run multiple containers
For this demo I will be using Windows 2016 VM created in Azure.
With windows 2016, container is feature which can be enabled .

Install or getting already a VM from Azure
lets to docker hub where public repositories exits
search for "microsoft nanoserver dotnet"

First you need to pull this image on to the server
docker pull microsoft/dotnet-nightly:nanoserver
It will download only the changes if you have previously downloaded. you can see all the images on your machine downloaded by
docker images

Lets run this image and see what we have on this.
docker run -it -p:5000:5000 c11


Lets build a sample .NET ASP.NET web application interactively
We are doing this just to find out what we have in container and if needed what we can do to container. In reality we will automate this with external docker configuration file ( we will see this shortly after this manual steps)

see what containers are running
docker ps
browse the web page

Lets customize this Web app with custom authentication
After this customization, we will see Login page with both Microsoft and Custom authentication buttons. For this we need to copy the files from host machine directory to container. while running container we can map the volumes from host to container where container can get access to host directory
Lets do run with shared folder mapping
docker run -it -p:5000:5000 -v c:\testing:c:\hosttesting c113

Copy files from host directory to enable custom authentication

browse the page and navigate to Login page

Containers are read only that means if we remove this container we loose everything. In order to save this we can use commit command to save it to new image with our current settings so that we can re create with current status.
docker commit repostory:tag
![]()
We can run with this new image and everything remains same where we can see the custom files copied over with dotnet web app.
Run the newly saved image

see the new image

##Now that we have done ASP.NET web app manually lets do automate OAuth . As we have built our web app manually lets automate the build process for OAuth server. For automation we need a docker file with set of instructions.
FROM microsoft/windowsservercore
ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 4.4.5
ENV NODE_SHA256 7b2409605c871a40d60c187bd24f6f6ddf10590df060b7d905ef46b3b3aa7f81
RUN powershell -Command \
wget -Uri https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-x64.msi -OutFile node.msi -UseBasicParsing ; \
if ((Get-FileHash node.msi -Algorithm sha256).Hash -ne $env:NODE_SHA256) {exit 1} ; \
Start-Process -FilePath msiexec -ArgumentList /q, /i, node.msi -Wait ; \
Remove-Item -Path node.msi
#make a directory in container
RUN mkdir c:\oauthserver
# copy src from host to simulator
copy oauthserver\\src C:\oauthserver
# make simulator as working directory
WORKDIR c:\\oauthserver
# download the packages in container
RUN npm install
EXPOSE 5001
# make starting command as npm
CMD [ "npm.cmd", "start" ]docker build -f .\oauth.dockerfile -t oauthdemo:test .

see the new image created.

run the image in background ( instead of interactive )

get the ipd address
docker inspect | sls ipadd

Running multiple containers
Now the we have run web app and oauth server containers (web app manually and automated oauth) lets see how we can automate running these 2 containers simultaneously and web app communicate to oAuth server.
docker-compose is the tool one can use to build, run, stop multiple containers at the same time.
docker-compose build uses the docker-compose.yml to build
version: '2.1'
services:
oauth:
build:
context: .
dockerfile: oauth.dockerfile
ports:
- "5001:5001"
networks:
default:
ipv4_address: 172.23.2.53
web:
build:
context: .
dockerfile: web.dockerfile
networks:
default:
ipv4_address: 172.23.2.54
ports:
- "5000:5000"
links:
- oauth
networks:
default:
external:
name: natdocker-compose build

List the network with containers

Inspect the network which shows the ipaddress and other info

Logging with custom authentication provider

Lets address Software deployment issue now
As we have seen the containers in action our software deployment can be converted like below
- Build servers will produce images with loaded software ( instead of setup.exe/*.msi )
- Build servers will publish these images in central repository (either private or public)
- Deployment servers (either physical or VMs) will use docker run
to run the software

