Docker binary code compilation

Source: Internet
Author: User
Tags docker run

Contents

  • Docker binary code compilation process
  • Other compilation methods
  • Makefile
Docker binary code compilation process

How to compile docker is introduced on the official website.

In fact, it is very simple, that is, there is a MAKEFILE file in the docker source code, execute make, you can compile.

Let's take a look at the make process from the source code.

First, let's take a look at makefile.

...DOCKER_MOUNT := $(if $(BINDDIR),-v "$(CURDIR)/$(BINDDIR):/go/src/github.com/docker/docker/$(BINDDIR)")DOCKER_RUN_DOCKER := docker run --rm -it --privileged -e TIMEOUT -e BUILDFLAGS -e TESTFLAGS -e TESTDIRS -e DOCKER_GRAPHDRIVER -e DOCKER_EXECDRIVER $(DOCKER_MOUNT) "$(DOCKER_IMAGE)"...binary: build   $(DOCKER_RUN_DOCKER) hack/make.sh binary...build: bundlesdocker build -t "$(DOCKER_IMAGE)" ....bundles:   mkdir bundles

Run make binary. Will first create the bundles folder, then execute docker build, and create an image through dockerfile (this step can actually be done directly from the pull image on the official website without having to build it by yourself, as detailed below ). Then run the container, bind the bundles in the container to the bundles folder in the path of the physical machine through the-V parameter, and then start the container. The container runs the hack/dind command to compile docker and put the compiled file in bundles. This is also visible on the physical machine.

Docker binary code compilation adopts a very dockerful method. Because building a docker compiling environment may be cumbersome, docker directly provides a docker-dev image to users. You can download the image directly. You only need to download this image to compile the docker binary code in this image. Another method is to use dockerfile for build to obtain the image. The dockerfile is in the root directory of the docker source code. This method is time-consuming and not recommended.

With the docker-dev image, you don't need to build the image every time, but you only need to use the original image. Then I modified the MAKEFILE file to support the use of the docker-dev image for compilation. The updated makefile is included at the end.

I support multiple methods to flexibly use the local environment:

Make docker_command = build by using build (by default, the same docker-dev image of pull and the current version) Make specifies the local image through the pull method (no longer pull image) make docker_image = docker-Dev: v1.2
Other compilation methods

Another method is to upload your code to GitHub.

Then on the https://registry.hub.docker.com, register, select your own GitHub project for automatic compilation.

This method is really slow and cannot be obtained within half an hour (measured in 20 minutes), although officially recommended. But I feel like a hard advertisement for myself...

Makefile
.PHONY: all binary build cross default docs docs-build docs-shell shell test test-unit test-integration test-integration-cli test-docker-py validate# env vars passed through directly to Docker‘s build scripts# to allow things like `make DOCKER_CLIENTONLY=1 binary` easily# `docs/sources/contributing/devenvironment.md ` and `project/PACKAGERS.md` have some limited documentation of some of theseDOCKER_ENVS :=    -e BUILDFLAGS    -e DOCKER_CLIENTONLY    -e DOCKER_EXECDRIVER    -e DOCKER_GRAPHDRIVER    -e TESTDIRS    -e TESTFLAGS    -e TIMEOUT# note: we _cannot_ add "-e DOCKER_BUILDTAGS" here because even if it‘s unset in the shell, that would shadow the "ENV DOCKER_BUILDTAGS" set in our Dockerfile, which is very important for our official builds# to allow pull docker-dev image from registry.hub.docker.com and avoid building every time# allow `make DOCKER_COMMAND=build` to build image from DockerfileDOCKER_COMMAND := pullDOCKER_VERSION := $(shell cat VERSION)# to allow `make BIND_DIR=. shell` or `make BIND_DIR= test`# (default to no bind mount if DOCKER_HOST is set)# note: BINDDIR is supported for backwards-compatibility hereBIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,bundles))DOCKER_BUILD_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)")DOCKER_PULL_MOUNT := -v "$(CURDIR):/go/src/github.com/docker/docker"# to allow `make DOCSDIR=docs docs-shell` (to create a bind mount in docs)DOCS_MOUNT := $(if $(DOCSDIR),-v $(CURDIR)/$(DOCSDIR):/$(DOCSDIR))# to allow `make DOCSPORT=9000 docs`DOCSPORT := 8000GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)# to allow you miss .git directoryDOCKER_ENVS += $(if $(GIT_BRANCH),,-e DOCKER_GITCOMMIT=$(DOCKER_VERSION))DOCKER_BUILD_IMAGE := docker$(if $(GIT_BRANCH),:$(GIT_BRANCH))DOCKER_PULL_IMAGE := docker-dev:$(if $(DOCKER_VERSION),$(DOCKER_VERSION))# to allow `make DOCKER_IMAGE=docker-dev:v1.2`(to use some other image if needed)ifeq ($(DOCKER_COMMAND),pull)   DOCKER_IMAGE := $(DOCKER_PULL_IMAGE)   DOCKER_MOUNT := $(DOCKER_PULL_MOUNT)else   DOCKER_IMAGE := $(DOCKER_BUILD_IMAGE)   DOCKER_MOUNT := $(DOCKER_BUILD_MOUNT)endifDOCKER_DOCS_IMAGE := docker-docs$(if $(GIT_BRANCH),:$(GIT_BRANCH))DOCKER_RUN_DOCKER := docker run --rm -it --privileged $(DOCKER_ENVS) $(DOCKER_MOUNT) "$(DOCKER_IMAGE)"DOCKER_RUN_DOCS := docker run --rm -it $(DOCS_MOUNT) -e AWS_S3_BUCKET -e NOCACHE# for some docs workarounds (see below in "docs-build" target)GITCOMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)default: binaryall: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.shbinary: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh binarycross: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh binary crossdocs: docs-build   $(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 "$(DOCKER_DOCS_IMAGE)" mkdocs servedocs-shell: docs-build   $(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 "$(DOCKER_DOCS_IMAGE)" bashdocs-release: docs-build   $(DOCKER_RUN_DOCS) -e OPTIONS -e BUILD_ROOT -e DISTRIBUTION_ID       -v $(CURDIR)/docs/awsconfig:/docs/awsconfig       "$(DOCKER_DOCS_IMAGE)" ./release.shdocs-test: docs-build   $(DOCKER_RUN_DOCS) "$(DOCKER_DOCS_IMAGE)" ./test.shtest: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh binary cross test-unit test-integration test-integration-cli test-docker-pytest-unit: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh test-unittest-integration: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh test-integrationtest-integration-cli: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh binary test-integration-clitest-docker-py: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-pyvalidate: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) hack/make.sh validate-gofmt validate-dco validate-tomlshell: $(DOCKER_COMMAND)   $(DOCKER_RUN_DOCKER) bashpull:   docker pull "$(DOCKER_IMAGE)"build: bundles   docker build -t "$(DOCKER_IMAGE)" .docs-build:   git fetch https://github.com/docker/docker.git docs && git diff --name-status FETCH_HEAD...HEAD -- docs > docs/changed-files   cp ./VERSION docs/VERSION   echo "$(GIT_BRANCH)" > docs/GIT_BRANCH#  echo "$(AWS_S3_BUCKET)" > docs/AWS_S3_BUCKET   echo "$(GITCOMMIT)" > docs/GITCOMMIT   docker build -t "$(DOCKER_DOCS_IMAGE)" docsbundles:   mkdir bundles

Copy the makefile to your own docker project.



From Weizhi note (wiz)



Docker binary code compilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.