Beginning in Windows 10 Insider Build 17063, we’re introducing two command-line tools to the Windows toolchain: curl and bsdtar. It’s been a long time coming, I know. We’d like to give credit to the folks who’ve created and maintain bsdtar and curl—awesome open-source tools used by millions of humans every day. Let’s take a look at two impactful ways these tools will make developing on Windows an even better experience.

1. Developers! Developers! Developers!

Tar and curl are staples in a developer’s toolbox; beginning today, you’ll find these tools are available from the command-line for all SKUs of Windows. And yes, they’re the same tools you’ve come to know and love! If you’re unfamiliar with these tools, here’s an overview of what they do:

  • Tar: A command line tool that allows a user to extract files and create archives. Outside of PowerShell or the installation of third party software, there was no way to extract a file from cmd.exe. We’re correcting this behavior :) The implementation we’re shipping in Windows uses libarchive.
  • Curl: Another command line tool that allows for transferring of files to and from servers (so you can, say, now download a file from the internet).

Now not only will you be able to perform file transfers from the command line, you’ll also be able to extract files in formats in addition to .zip (like .tar.gz, for example). PowerShell does already offer similar functionality (it has curl and it’s own file extraction utilities), but we recognize that there might be instances where PowerShell is not readily available or the user wants to stay in cmd.



2. The Containers Experience

Now that we’re shipping these tools inbox, you no longer need to worry about using a separate container image as the builder when targeting nanoserver-based containers. Instead, we can invoke the tools like so:

#Specify the base image
FROM microsoft/nanoserver-insider:latest
#Download the package we want and unzip it to our destination
RUN curl.exe -o node.zip https://nodejs.org/dist/v9.2.0/node-v9.2.0-win-x64.zip && \
mkdir "C:\\Program Files\\node" && \
tar.exe -xf node.zip -C "C:\\Program Files\\node" --strip-components=1
#Add node to PATH
ENV PATH “C:\\Program Files\\node:%PATH%”
#Start Node
CMD [ “node.exe” ]

Background

We offer two base images for our containers: windowsservercore and nanoserver. The servercore image is the larger of the two and has support for such things as the full .NET framework. On the opposite end of the spectrum is nanoserver, which is built to be lightweight with as minimal a memory footprint as possible. It’s capable of running .NET core but, in keeping with the minimalism, we’ve tried to slim down the image size as much as possible. We threw out all components we felt were not mission-critical for the container image.

PowerShell was one of the components that was put on the chopping block for our nanoserver image. PowerShell is a whopping 56 Mb (given that the total size of the nanoserver image is 200 Mb…that’s quite the savings!) But the consequence of removing PowerShell meant there was no way to pull down a package and unzip it from within the container.

FROM microsoft/windowsservercore
#This call would fail because we don’t have powershell…
RUN powershell.exe -Command `
$ErrorActionPreference = 'Stop'; `
wget https://www.python.org/ftp/python/3....thon-3.5.1.exe -OutFile c:\python-3.5.1.exe ; `
Start-Process c:\python-3.5.1.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; `
Remove-Item c:\python-3.5.1.exe -Force

If you’re familiar with writing dockerfiles, you’ll know that it’s common practice to pull in all the packages (node, mongo, etc.) you need and install them. Instead, users would have to rely on using a separate image with PowerShell as the “builder” image to accomplish constructing an image. This is clearly not the experience we want our users to have when targeting nanoserver—they’d end up having to download the much larger servercore image.

This is all resolved with the addition of curl and tar. You can call these tools from servercore images as well.



Source: Tar and Curl Come to Windows! | Virtualization Blog