Understanding the Dockerfile

The Dockerfile is the source code for an image. The complete code for the PowerShell image is just three lines:

FROM microsoft/nanoserverCOPY scripts/print-env-details.ps1 c:\\print-env.ps1CMD ["powershell.exe", "c:\\print-env.ps1"]

It's pretty easy to guess what's happening even if you've never seen a Dockerfile before. By convention, the instructions (FROM, COPY and CMD) are uppercase and the arguments are lowercase, but that's not mandatory. Also by convention, you save the text in a file called Dockerfile, but that's not mandatory either (a file with no extension looks odd in Windows, but remember that Docker's heritage is in Linux).

Let's take a look at the instructions in that Dockerfile line by line:

Get Docker on Windows now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.