how to build docker
tags: container
how to build docker
1. build
根据docker官方文档,一步步来即可。
1.清空容器、镜像等避免影响build过程
docker system prune -a
docker volume prune
2.下载代码
git clone https://github.com/moby/moby.git
3.进入docker提供的编译环境
cd moby
make BIND_DIR=. shell
等待约15分钟,会进入到一个容器
root@7fd23c4e7515:/go/src/github.com/docker/docker#
4.修改代码
修改cmd/dockerd/docker.go
中的代码
sed -i "s@build %s@build %s, modified by st0n3@g" cmd/dockerd/docker.go
5.build
hack/make.sh binary install-binary
6.binary
build好的二进制文件位于/go/src/github.com/docker/docker/bundles/binary-daemon
root@7fd23c4e7515:/go/src/github.com/docker/docker/bundles/binary-daemon# ./dockerd --version
Docker version dev, build d086c52c9a, modified by st0n3
2. troubleshooting
2.1 GFW
配置systemd代理
https://docs.docker.com/config/daemon/systemd/
也可以使用socks协议
[Service]
Environment="HTTP_PROXY=socks5://172.17.0.1:1082/"
Environment="HTTPS_PROXY=socks5://172.17.0.1:1082/"
使用以下命令获取环境或编译二进制
make DOCKER_BUILD_APT_MIRROR=ftp.cn.debian.org BIND_DIR=. shell
或
make DOCKER_CROSS=false build
遇到错误,就在对应的镜像下配置代理,例如
FROM base AS swagger
ENV http_proxy="socks5://172.17.0.1:1082"
ENV https_proxy="socks5://172.17.0.1:1082"
如果遇到go语言相关错误, 配置goproxy, 例如
FROM base AS golangci_lint
ENV GOPROXY=https://goproxy.cn,direct
socks协议可能对部分镜像无效, 则可以使用http代理, 例如
FROM dev-base AS tini
ENV http_proxy="http://172.17.0.1:8118"
ENV https_proxy="http://172.17.0.1:8118"
我改过的地方如下:
...
FROM base AS swagger
ENV http_proxy="socks5://172.17.0.1:1082"
ENV https_proxy="socks5://172.17.0.1:1082"
...
FROM base AS vndr
ENV http_proxy="socks5://172.17.0.1:1082"
ENV https_proxy="socks5://172.17.0.1:1082"
...
FROM dev-base AS proxy
ENV http_proxy="socks5://172.17.0.1:1082"
ENV https_proxy="socks5://172.17.0.1:1082"
...
FROM base AS golangci_lint
ENV GOPROXY=https://goproxy.cn,direct
...
FROM base AS gotestsum
ENV GOPROXY=https://goproxy.cn,direct
...
FROM base AS shfmt
ENV GOPROXY=https://goproxy.cn,direct
...
FROM dev-base AS dockercli
ENV http_proxy="socks5://172.17.0.1:1082"
ENV https_proxy="socks5://172.17.0.1:1082"
...
FROM dev-base AS rootlesskit
ENV http_proxy="socks5://172.17.0.1:1082"
ENV https_proxy="socks5://172.17.0.1:1082"
...
2.2 Cannot autolaunch D-Bus without X11 $DISPLAY
https://ug.epurs.com/post/docker-login-error-saving-credentials/