As Docker continues to grow we are starting to see the containerization engine more and more on Windows. With the need for containers on Windows, we also need the same automation we get in Linux with Dockerfiles. Today we're going to create a Dockerfile that runs PowerShell cmdlets.
1. Docker for Windows
2. A code editor (VSCode preferred)
Let's go ahead and get our Dockerfile set up. Below is the Dockerfile I used for this post.
As you can see from the below, this is a tiny Dockerfile. What this will do install is install the IIS Windows Feature and create a new file in
C:\ called config
from mcr.microsoft.com/windows/servercore:1903 MAINTAINER Michael Levan RUN powershell -Command Install-WindowsFeature -Name Web-Server RUN powershell -Command New-Item -Type File -Path C:\ -Name config
Next let's create a running container out of our image. First we'll need to run
docker image ls to get our Image ID. Then we'll create a new container by running
docker run -tid containerId
Now it's time to exec into the container. Let's
run docker exec -ti containerid powershell to create a session into the container from our terminal. You should see a scree similar to the one below. Looks like a regular terminal, right?
Let's go ahead and check for IIS by running
Get-WindowsFeature -Name Web-Server to confirm IIS successfully installed.
Now that we know it's installed, let's curl our localhost to confirm IIS isrunning. Run
curl localhost --UseBasicParsing and you should see a GET request and a 200 return code.
And just like that you have successfully deployed IIS in a Docker image and created a container from that Docker image! Thanks for reading.