Deploying Docker Containers on Windows Server using Docker file

Posted: December 16, 2016 in Windows Server

Docker file enable us to quickly deploy Docker containers,we can customize container (add features,create files/folers,copy files from docker host,run startup script…)

This section specify Docker images from which we will derive container

FROM nanoserver/iis

Optionally,define “responsible” persron (who created this image)

MAINTAINER dragan979@yahoo.com

This image has built-in IIS server,in this example we simple deleted default HTML page

RUN del C:\inetpub\wwwroot\iisstart.htm

Create new default IIS page

RUN echo “Greetings from iis container” > c:\inetpub\wwwroot\index.html

Creating new folder in Docker container (note forward slash)

RUN powershell New-Item -ItemType directory -Path c:/test

copy C++ redistributable from Docker host to Docker (to folder created in previous step)

COPY vcredist_x86.exe c:/test/

Copy PS script to Docker container (this script simply restarts IIS service) (note forward slash)

COPY start.ps1 c:/test/

Create new empty file in Docker container (note forward slash)

RUN powershell new-item c:/test/file.txt

Install vcredist_x86.exe

RUN powershell start-process C:\test\vcredist_x86.exe -ArgumentList ‘/quiet’

Run PS script copied in previous step

RUN powershell.exe -executionpolicy bypass c:\test\start.ps1

Download python to c:\test (note forward slash)

ADD https://www.python.org/ftp/python/3.5.1/python-3.5.1.exe c:/test/python-3.5.1.exe

Complete docker file (this file has no extension)

# Sample Dockerfile

# Indicates that the windowsservercore image will be used as the base image.
FROM nanoserver/iis

# Metadata indicating an image maintainer.
MAINTAINER dragan979@yahoo.com

# Creates an HTML file and adds content to this file.

RUN del C:\inetpub\wwwroot\iisstart.htm
RUN echo "Greetings from iis container" > c:\inetpub\wwwroot\index.html
RUN powershell New-Item -ItemType directory -Path c:/test
COPY vcredist_x86.exe c:/test/
COPY start.ps1 c:/test/
RUN powershell new-item c:/test/file.txt
RUN powershell start-process C:\test\vcredist_x86.exe -ArgumentList '/quiet'
RUN powershell.exe -executionpolicy bypass c:\test\start.ps1
ADD https://www.python.org/ftp/python/3.5.1/python-3.5.1.exe c:/test/python-3.5.1.exe

Make sure PowerShell script,vcredist and Docker file is in the current location of CMD or PowerShell (for example if PS or CMD prompt is in C:\Users\username all these files also should be located in that path)

From CMD or PowerShell prompt run:

docker build -t iis .

Note period (.) at the end it means current folder (it defines path of Docker file).

iis is container name

All steps specified in Docker file are execured in order

untitled

Run Docker container:

docker run -it -p 80:80 iis powershell

2

Storing container into https://hub.docker.com

I created private registry (“store” for Docker images)

3

Log in to Docker Hub

docker login

1

Rename our Docker image to be the same as name of Docker Hub registry-dragan979/test in my case (in order to be able to “upload” image into Docker Hub)

docker tag iis dragan979/test

Upload image to Docker Hub

docker push dragan979/test
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s