TECHNICAL DOCS

Running powershell, bash, and EXEs from the dockerfile

Windocks supports the running of EXEs, Powershell scripts, Windows commands, Bash from the dockerfile. This is available in Enterprise edition. These commands can be run at image build time, container create time, or after container start. See the sample in windocks\samples\powershellOnDatabase

 

 

Specifying commands to run in the dockerfile

The dockerfile specifies WHEN to run the Powershell or EXEs. There are 4 choices on when to run the Powershell or EXEs.

  • Image build time
  • Image build time after the image databases are ready
  • When a container is created from this image
  • When a container is created from this image time after the container databases are ready

First create the dockerfile as follows (# is used for commenting lines):

dockerfile

FROM mssql-2016

SETUPCLONING FULL customers C:\windocks\dbbackups\customerdatafull.bak

# COPY powershellScriptAtCreate.ps1 .

# COPY custom.exe .

COPY mask.ps1 .

COPY deploy.ps1 .

# This Powershell runs at image build time but NOT on the image databases RUN somePowershell.ps1 # This Powershell runs on the database in the image at image build time
# Because the powershell is run on the image databases, all containers created from this image will have the effects of this script
# $ContainerDir and $ContainerPort are populated by Windocks automatically with the values of the container used to build the image.

RUN RUN_ON_IMAGE_DATABASES powershell.exe $ContainerDir\mask.ps1 -dest LAPTOP-DA9D6LTM\INSTANCE$ContainerPort

# Anything below this line runs after a container create is created from the image

ENV USE_DOCKERFILE_TO_CREATE_CONTAINER=1


# This Powershell runs at container create time. This container is the one being created by the user and NOT the container used to build the image
# $ContainerDir is populated by Windocks automatically with the actual values for the container created by the user

RUN powershell.exe $ContainerDir\powershellScriptAtCreate.ps1


# You may also run EXEs like Powershell # RUN .\custom.exe $ContainerPort


# This Powershell runs on container create after the container databases are ready
# $ContainerDir and $ContainerPort are populated by Windocks automatically. The instance name for the SQL container is INSTANCE$ContainerPort

RUN RUN_ON_CONTAINER_START powershell.exe $ContainerDir\deploy.ps1 -dest LAPTOP-DA9D6LTM\INSTANCE$ContainerPort

 

 

Building the image from the dockerfile 

In a command line on the Windocks server:
docker build -t yourimagename path\to\directory\containing\dockerfile

Alternatively, use the web application and click on Build in the top menu and click Browse. Select all the files in the directory (dockerfile, any script files) and then Open. Then click Build.

You may also use the REST API to build the image

 

 

Creating the container / clone

Create a container / clone from the image with the powershell executed. This can be done using a command line (only on the Windocks machine), or the web application (from any machine) or from the REST API (any machine)

In a command line on the Windocks server:
docker run -d yourimagename

This will deliver a writeable database clone and the Powershell scripts run

You may use the web application at ServerIp:/index.html or the file windocks\ui\index.html in Chrome or Firefox

You may also use the REST API here

Extend CI/CD to your data layer