Docker source code reading (2) - Docker source code (Moby) compiled and run under windows

foreword

Regarding the installation of the Docker source code in the Linux environment, I have already introduced it in the first article of this series, and it is quite simple overall. Later, I tried to compile moby in the windows environment. After stepping on countless pitfalls, I finally compiled it successfully.

Note: To compile moby under windows, the network environment is more complicated, and the agent needs to open the TUN mode. For the specific method, search by yourself

build environment

  1. To ensure that docker is running in windows containers mode, right-click the docker icon, and then see that it is already in Switch to Linux containerswindows containers, if not, click to switch to windows containers
    insert image description here

  2. Build the base image
    into the moby folder, then

docker pull mcr.microsoft.com/windows/servercore:ltsc2022
docker image tag mcr.microsoft.com/windows/servercore:ltsc2022 microsoft/windowsservercore
docker build -t nativebuildimage -f .\Dockerfile.windows .

Here is a bit of official documentation. There is only one sentence docker build -t nativebuildimage -f .\Dockerfile.windows . After execution, an error will definitely be reported, because this image has long been abandoned pull access denied
for microsoft/windowsservercore, repository does not exist or may require 'docker login': denied: requested access to the resource is de Nied Later, I found his workflow and took a look at the commands executed by the test, only to find out that it needs to be done like
this
insert image description here

During the construction process, if a network error occurs, it means that no real global proxy is set, and you can search for how to set the TUN mode of the proxy by yourself.

  1. Compile the binary
$DOCKER_GITCOMMIT=(git rev-parse --short HEAD)
docker run --name binaries -e DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT nativebuildimage hack\make.ps1 -Binary
  1. Copy generated files
    The following two lines of commands will copy the built docker and dockerd to the current folder
docker cp binaries:C:\gopath\src\github.com\docker\docker\bundles\docker.exe docker.exe
docker cp binaries:C:\gopath\src\github.com\docker\docker\bundles\dockerd.exe dockerd.exe
  1. implement
Stop-Service Docker
.\dockerd.exe -D

The docker daemon starts successfully
insert image description here
Note here that the docker daemon listens at ./pipe/docker_engine_windows
so here we have to execute the command like this:

.\docker -H=npipe:./pipe/docker_engine_windows version

insert image description here
Successful execution~~

Then, as before, we modify the shorts in the source code cmd/docerd/docker.go
insert image description here
and recompile according to the 2, 3, 4, 5 process, and finally succeed, as shown in the figure:
insert image description here

Guess you like

Origin blog.csdn.net/x646602196/article/details/131111797