Skip to content

Add initial support building Windows docker in docker - #18348

Merged
jessfraz merged 1 commit into
moby:masterfrom
hypriot:add-dockerfile-for-windows
Jan 15, 2016
Merged

jessfraz merged 1 commit into
moby:masterfrom
hypriot:add-dockerfile-for-windows

Conversation

@StefanScherer

Copy link
Copy Markdown
Contributor

This PR is a proof of concept to simplify setting up a Windows build environment to build the Docker Engine for Windows.

After following the discussion in #18206 and reading the documentation http://docs.docker.com/opensource/project/software-req-win/ by @jfrazelle I thought there should be an easier way for anybody in the community who wants to start contributing to the effort to bring docker to the Windows platform.

And after testing Docker on TP4 for a while I was sure the time has come to use Docker for a first real task to solve. So I tried to build docker in docker on Windows to keep the host machine clean.

I agree with @jhowardmsft to use just native Windows tools and PowerShell to work on a Windows host. So I tried to follow that path, keeping away from MinGW/Cygwin shells and just use the tools given on Windows plus an absolute minimum number external tools.

To reproduce the build you need

  1. Windows Server 2016 TP4 with Docker installed
  2. Git for Windows to clone the GitHub repo.
  3. There is no step three.

These are the detailed steps by using Chocolatey to install git and clone the PR branch:

iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco install -y git -params "/GitAndUnixToolsOnPath"
git clone -b add-dockerfile-for-windows https://github.com/hypriot/docker
cd docker
.\hack\make.ps1

The hack\make.ps1 script is used both on the host as well inside the Docker container.

  • First a Docker image is built with the Dockerfile.windows file to install the tools needed like Go 1.5.1, rsrc, TDM-GCC and so on.
  • Then the script starts a Docker container with a volume mounted to the bundles directory and the final docker binary will be copied to the host into bundles\docker.exe.
  • Inside the container I encountered a small bash script hack\make\.go-autogen which the PowerShell script just converts to PowerShell and runs these steps as well.

Then as an admin you can replace your Docker Engine with

stop-service docker
cd C:\Windows\system32
copy docker.exe docker-tp4.exe
copy $env:USERPROFILE\docker\bundles\docker.exe docker.exe
start-service docker

After updating the Docker EngineI had the effect that some Container images get lost and I had to tag the base container images with the latest tag again. But this stills proofs me that Docker on Windows is the right thing to do and to push forward. And it will change the way we develop and work on Windows as we can see it on Linux.
Thanks to all the effort of the Microsoft team (@ahmetalpbalkan @darrenstahlmsft @taylorb-microsoft ...) to get to this point!

docker-in-docker-works

PS: Now I can start contributing as well and not just annoy you with GitHub issues ;-)

@thaJeztah

Copy link
Copy Markdown
Member

Oh, this is cool! Thanks!

@jessfraz

jessfraz commented Dec 1, 2015

Copy link
Copy Markdown
Contributor

ping @jhowardmsft

@jterry75

jterry75 commented Dec 1, 2015

Copy link
Copy Markdown
Contributor

Windows now supports a package management system called One-Get. You can instead use:

Install-Package docker -ProviderName chocolatey
Install-Package git -ProviderName chocolatey

The plus being this works from a 100% clean install of Windows with no dependency resolution. But the rest of your workflow is the same after that point.

@lowenna

lowenna commented Dec 1, 2015

Copy link
Copy Markdown
Member

Very cool :)

Comment thread hack/make.ps1 Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wouldn't it better just to have a .go-autogen.ps1 checked in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After looking at it, I think so. I started with a few patches, but ended up with more and more regexes to make it work.

@ahmetb

ahmetb commented Dec 1, 2015

Copy link
Copy Markdown
Contributor

This is very cool!

@jterry75 I own the docker package on Chocolatey, I'll let @StefanScherer figure out how we ship it with chocolatey, whether it should be client-only or both. Maybe we need a separate docker-engine package for this, I'm not sure how the executable would behave on a non-TP4 Windows machine.

Comment thread Dockerfile.windows Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not real wget is it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is PowerShell, not a wget.exe. It is the shortest way to write it in PowerShell I think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm alright, I don't know much about it, I think it's just an alias. If it's a short alias, then we should probably use the canonical command instead.

@StefanScherer

Copy link
Copy Markdown
Contributor Author

@jterry75 Thank you for the hint. You do not need to install the docker client on a TP4, because you need to install the Docker Engine on it which needs some more features to be installed ( wget -uri https://aka.ms/tp4/Install-ContainerHost -OutFile C:\Install-ContainerHost.ps1 ... ).

Installing git with

Install-Package git -ProviderName chocolatey

has a slight problem that git could not be found in the currently open PowerShell terminal. Even after logoff and logon I could not find git in PATH. So I keep at the classical way to get Chocolatey installed for now.

Comment thread hack/make.ps1 Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know if any other options should be set to build the docker engine. My breakthrough was with autogen daemon.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's all that's technically needed (what I use for local development). The official cross build uses (you can just echo in hack/make/binary where it does the go build) the following for the Windows binary 64-bit binary:

Buildflags -a -tags autogen netgo static_build sqlite_omit_load_extension apparmor selinux journal btrfs_noversion libdm_no_deferred_remove -installsuffix netgo. Obviously some of those aren't strictly relevant.
ldflags -w
ldflags_static empty

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, plus daemon....

@StefanScherer

Copy link
Copy Markdown
Contributor Author

@jhowardmsft Do you or someone of the Docker team at Microsoft know if it is allowed to push such a Win2016TP+Docker Vagrant basebox to Atlas, so the community could grow testing, playing, contributing back to Docker on Windows through a Vagrant box more easily?

I know how cool it is to run TP4 on Azure, but I'm still happy to have a TP4 locally on my Mac to show it offline as well. A Packer template to reproduce such a Vagrant box can be found here.

@lowenna

lowenna commented Dec 1, 2015

Copy link
Copy Markdown
Member

I steer clear of licensing questions. But I would be extremely doubtful this would be permitted.

Comment thread hack/make.ps1 Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Trying to figure out why the cp to bundles. It's invoked on L54 as hack\make.go-autogen.ps1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll remove this line. This was to test whether all the environments were set. I got only library-import but then found out that I have to set the buildtags.

@thecloudtaylor

Copy link
Copy Markdown

@StefanScherer re-TP4 vagrant image in Atlas - I'll look into it.

@thaJeztah

Copy link
Copy Markdown
Member

@StefanScherer what's the status here? I see some comment, are they all addressed? (just a status check ❤️)

@StefanScherer
StefanScherer force-pushed the add-dockerfile-for-windows branch from 6ae9193 to bcb0209 Compare December 17, 2015 00:10
@StefanScherer

Copy link
Copy Markdown
Contributor Author

@thaJeztah I've rebased and updated the code:

  • Instead of converting the bash script hack/make/.go-autogen.sh I have added the PS1 variant. This is more readable than the bunch of regexes.
  • The docker.exe will be built into bundles/1.10.0-dev/docker.exe

@thaJeztah

Copy link
Copy Markdown
Member

Thanks @StefanScherer!

ping @jfrazelle how should we proceed here? I think some people are on vacation currently, should we wait until after the Holidays?

@lowenna

lowenna commented Jan 13, 2016

Copy link
Copy Markdown
Member

@StefanScherer I've been doing a bunch of work around bringing up Windows CI (against Windows) and have a slight change of heart here. I don't think at this point we should be duplicating the current hack\make scripts, but rather embrace what's there currently (ie build using sh hack\make.sh). IMO that's a lot less error prone in the longer term. Also there's a lot more bash scripters in the overall docker community right now who can assist debugging what's going on should it at some point fail.

That said, sh doesn't (yet) work in a container - we're debugging as to why and hope to have that fixed soon.

So for now, I believe you should update this PR to just add the dockerfile.windows. I have also been modifying it so that it works under TP5 builds, and uses the latest version of go/git. You can find that at https://gist.github.com/jhowardmsft/b9413e30ece1d4cf8465. Could you use that version? Or I can open a new PR if that's easier. ❤️

@StefanScherer

Copy link
Copy Markdown
Contributor Author

@jhowardmsft I've seen the PR's regarding Windows CI 👍

Oh, seems we are walking different directions. I'm getting used to PowerShell and posh-git having a git prompt - wow, all native Windows. And now that 😨 OK, I'm just kidding 😃 So no different directions, but coming closer.
And once inside the container it doesn't really matters what has to be installed inside.

The gist looks really good. I'll test it on TP4 and figure out what I have to install in addition now in my docker-windows-box. I'll update this PR.

@StefanScherer
StefanScherer force-pushed the add-dockerfile-for-windows branch from bcb0209 to 376688d Compare January 14, 2016 00:33
@StefanScherer

Copy link
Copy Markdown
Contributor Author

@jhowardmsft Rebased and took your gist and removed the ps1 scripts 😢
So this should help PR #19316 .

@lowenna

lowenna commented Jan 14, 2016

Copy link
Copy Markdown
Member

LGTM :) One step closer to Windows to Windows CI becoming reality!

@mikedougherty @jfrazelle

@lowenna

lowenna commented Jan 14, 2016

Copy link
Copy Markdown
Member

@StefanScherer Can you rebase on master and force push? That will fix the failing test on Windows CI. Thx.

@StefanScherer
StefanScherer force-pushed the add-dockerfile-for-windows branch from 376688d to 6c88b8e Compare January 14, 2016 23:21
@StefanScherer

Copy link
Copy Markdown
Contributor Author

@jhowardmsft Rebased.

@thaJeztah

Copy link
Copy Markdown
Member

LGTM

ping @jfrazelle for review/merge

@jessfraz

Copy link
Copy Markdown
Contributor

super cool!

jessfraz pushed a commit that referenced this pull request Jan 15, 2016
Add initial support building Windows docker in docker
@jessfraz
jessfraz merged commit b70d615 into moby:master Jan 15, 2016
@jessfraz

Copy link
Copy Markdown
Contributor

LGTM

@thaJeztah

Copy link
Copy Markdown
Member

thanks @StefanScherer, really awesome job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants