Using the Newman Docker Image in Windows, Hassle-Free
Docker is one of the most well known container technologies and is quite the rage these days. We at Postman love Docker for its simplicity. It helps us by allowing a single software release to work on Windows, Mac-OSX and Linux, is extremely easy to set up, and abstracts away platform specific quirks of dependencies.
Last week, we released a Docker image that has Newman, Postman’s command line collection runner bundled with it. This blog post mainly deals with using the Newman docker image on Windows. Some of our users have mentioned issues installing the Newman CLI on Windows, so this workaround might help them.
Broadly, the process involves three steps:
- Installing Docker on Windows
- Configuring Docker to work on Windows Command Prompt
- Downloading and running the Newman Docker image
Installing Docker on Windows
If you don’t already have docker for windows installed on your system, follow these steps to install it. This process is also described in detail in the official Docker documentation.
- Download the setup (
docker-install.exe) for the latest release of “boot2docker”, which is a helper application that allows you to run Docker on windows. You can get the latest release here:
- Run the setup file downloaded in previous step. This will install the Docker Client for Windows, and other required components, such as Virtualbox and Git for Windows. Do restart your computer after installation.
- You should now see two new desktop icons, as shown below.
- Run (Double Click) the “Boot2Docker Start” shortcut. This will create a public/private key pair for you, and initialize a new virtualbox machine. If all goes well, you’ll see a shell as shown in the screengrab:
Note: On my system, I had to change BIOS settings and enable support for VT-x.
- Test your docker installation, run this in the shell:
$ docker run hello-world
That basically is the installation of the core part of Docker. What follows is a few tweaks so that we can run Docker from the Windows Command Prompt (
Configuring Docker to work on Windows Command Prompt
- Using docker with “cmd.exe” on Windows requires you to add a new directory to your system’s
%PATH%variable. You can add this by editing it in the system properties. Open
"My Computer" > "Properties" > "Advanced" > "Environment Variables" > "Path"and append
;C:\Program Files (x86)\Git\binto the value that is already present. If it’s blank, add
;C:\Program Files (x86)\Git\bin. Log out, and log back in to ensure that the changes to
%PATH%are propagated throughout your session.
- Open a new command prompt (cmd.exe) and type
You should see the directory you just added in the output.
- In the Command Prompt, run the following commands, which will initialize the Boot2Docker VM if initialization is not done already, and then start the VM.
$ boot2docker init $ boot2docker start
- Set the environment variables as mentioned in the output of previous step:
- Test your command line setup by running the docker “hello world” image:
$ docker run hello-world
Running Newman from Docker
You’re now all set to run docker from the windows Command Prompt. The rest of this tutorial assumes that you have a folder in your Desktop, called “collections” that has one Postman Collection file “testCollection.json”. Here’s how you can go about using Newman Docker image to run the “testCollection.json” file:
docker run -v /c/Users//Desktop/collections/:/tmp/collections -t postmanlabs/newman_ubuntu1404 -c /tmp/collections/testCollection.json
-v /c/Users//Desktop/collections/:/tmp/collections part instructs Docker to mount the windows “Desktop\collections” folder to “/tmp/collections” on the Newman Docker image. Mounting volumes in this way allows Newman to directly write to the mounted paths, enabling you to make use of the HTML output and other features.
Checkout the Newman-Docker GitHub repository for advanced usage!