Skip to content

Add Windows Dockerfile #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 1.6/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM windowsservercore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As on Linux I would see some sort of "buildpack-deps:jessie-scm" base image to have git (and svn, bzr, ...) installed to make go get work.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tianon - Ignore the Linux binary bit. That's a client-only thing, not in containers or in server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhowardmsft that makes me kind of sad, and I hope there are plans to change that because being able to docker run -it --rm ubuntu on Windows sounds really magical and I want it to be a thing 😇

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, but out of my hands.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe with a Hyper-V "Linux container": docker run -it --rm --isolation=hyperv ubuntu 😄


ENV GOLANG_VERSION 1.6.1
ENV GOLANG_DOWNLOAD_URL "https://golang.org/dl/go$GOLANG_VERSION.windows-amd64.zip"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need this - just build the URL in the DownloadFile command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's structured the same was as the Linux Dockerfiles: https://github.com/docker-library/golang/blob/master/1.6/Dockerfile#L11

ENV GOLANG_DOWNLOAD_SHA256 "1505afbcc5f71598c6ffd2a56ad550e4e8728c05649e9085f725e38d6b5a0fb8"

RUN powershell -Command \
$ErrorActionPreference = 'Stop'; \
(New-Object System.Net.WebClient).DownloadFile('%GOLANG_DOWNLOAD_URL%', 'go.zip') ; \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have ErrorActionPreference to stop, to ensure it returns failure at any point in the sequence. Again see dockerfile.windows in docker/docker for an example.

if ((Get-FileHash go.zip -Algorithm sha256).Hash -ne $env:GOLANG_DOWNLOAD_SHA256) {exit 1} ; \
Expand-Archive go.zip -DestinationPath c:\\ ; \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downloaded zip file should be checked as on Linux. I've added something in a node Docker image https://github.com/StefanScherer/dockerfiles-windows/blob/89f47847d082584c72741850119757414dda3625/node/5.10/Dockerfile#L10

   if ((Get-FileHash node.msi -Algorithm sha256).Hash -ne $env:NODE_SHA256) {exit 1} ; \

Remove-Item go.zip -Force

RUN setx /M PATH "C:\go\bin;%PATH%" && \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine these into a single command to avoid an extra layer. See dockerfile.windows in docker/docker for an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download-unzip and setx instructions? Again, this is structured like the linux image: https://github.com/docker-library/golang/blob/master/1.6/Dockerfile#L20 I don't think there's any harm in having this be separate layers since this sequencing doesn't cause bloat.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but less layers are quicker....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? It's the same number of bits over the wire (roughly), and it makes better use of caching because (for example) the RUN setx command (and subsequent ones) can be changed without having to re-run the the download and un-archive

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's miniscule but every msec counts. But realistically if you're worried about caching, surely the setx should go first? It's more likely the download will change, not the path...

Copy link
Contributor Author

@friism friism Apr 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhowardmsft but that would be semantically incorrect. Someone building the image and wanting to debug the layer after setx but before the download would run docker run -ti <layer-hash> cmd and be in a container with GOPATH and PATH pointing to a non-existent location.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You honestly believe that's a realistic scenario though? I really don't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some other reasons:

  1. it's how the Linux Dockerfiles are structured
  2. It reads better. If I'm scanning the Dockerfile top to bottom I'd see instruction setting PATH to random place not encountered before. Only scanning the next instruction do I realize that it's the eventual destination of the install of what's to come

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My $.02 - I truly don't buy that in something so simple. But your call as to what goes into any official images. Just giving my opinion 😄

setx /M GOPATH "C:\go"