Skip to content

Instantly share code, notes, and snippets.

@jamesattard
Last active June 10, 2019 06:23
Show Gist options
  • Save jamesattard/5d6b75b7d3ef2aac2ad37312d5fde30a to your computer and use it in GitHub Desktop.
Save jamesattard/5d6b75b7d3ef2aac2ad37312d5fde30a to your computer and use it in GitHub Desktop.
Docker Intro Session Exercise #2
# In this exercise we are going to automate Docker provisioning
# by using Dockerfiles.
#
# After completing this lab, you are expected to know how to:
#
# a. Understand what is a Dockerfile
# b. Build a Docker image from a Dockerfile
# c. Deploy applications inside a container
# d. Name and Tag images for later use
#
# Docker Intro Session Lab - James Attard (2019)
# Before we start, make sure that you still have the Powershell Nanoserver image created in the previous exercise.
docker run mcr.microsoft.com/powershell:6.2.1-nanoserver-1803
# Create a new directory where we place our powershell script and Dockerfile
mkdir windows-ps-demo
cd windows-ps-demo
# Place the attached Powershell script and Dockerfile inside the windows-ps-demo directory
cp HelloWorld.ps1 Dockerfile .
# To truly understand the potential of Dockerfiles, let's first deploy the application manually
# Create container and run Powershell script
docker create -t --name HelloNanoServerWorld -h NanoServer -i mcr.microsoft.com/powershell:6.2.1-nanoserver-1803
docker cp -a HelloWorld.ps1 HelloNanoServerWorld:HelloWorld.ps1
docker start HelloNanoServerWorld
docker exec HelloNanoServerWorld pwsh HelloWorld.ps1
# Now let's do the same thing with a Dockerfile
docker build -t hellonanoserverworld2 .
docker run --name mynanocontainer hellonanoserverworld2
FROM mcr.microsoft.com/powershell:6.2.1-nanoserver-1803
COPY HelloWorld.ps1 /
CMD ["pwsh", "HelloWorld.ps1"]
# Create a PowerShell Script for NanoServer
# Container Name HelloNanoServerWorld
# Demonstrated by James Attard
# June 2019
Write-Host ("Microsoft NanoServer Container") -ForegroundColor Green
Write-Host ("Operating System: $([Environment]::OSVersion.VersionString)") -ForegroundColor Red
Write-Host ("Hostname: $env:COMPUTERNAME") -ForegroundColor Magenta
Write-Host ("Username: $([Environment]::UserName) ") -ForegroundColor Yellow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment