Environment

Docker>19.03; Use 24.0.0 here

Steps

Compile

1
2
3
git clone https://github.com/docker/cli.git
cd cli
sudo docker buildx bake

Check

After the build process is complete, the Docker binary file can be found in /build. Please note that root privileges are required to execute the file.

1
2
3
4
sudo ls build/
#docker docker-linux-amd64

sudo ./build/docker version

The successful completion of the compilation process is indicated.:

1
2
3
4
5
6
7
8
9
Client:
Version: 24.0.0-rc.2-142-gdf04aca5d2.m
API version: 1.43 (downgraded from 1.44)
Go version: go1.20.5
Git commit: df04aca5d2
Built: Tue Jul 11 03:19:56 2023
OS/Arch: linux/amd64
Context: default
...

Troubleshooting

docker: ‘buildx’ is not a docker command after compiling error

Ref: https://askubuntu.com/questions/1467602/buildx-is-not-a-docker-command

Reinstall buildx toolkits:

1
2
sudo apt list --installed | grep buildx # Check its existance
sudo apt install docker-buildx-plugin # Reinstall it

dial tcp 142.251.42.241:443: connect: connection refused

1
2
3
4
5
6
7
8
9
10
11
12
13
------
> [goversioninfo 1/1] RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod GOBIN=/out GO111MODULE=on go install "github.com/josephspurrier/goversioninfo@v1.3.0":
21.45 go: github.com/josephspurrier/goversioninfo@v1.3.0: github.com/josephspurrier/goversioninfo@v1.3.0: Get "https://proxy.golang.org/github.com/josephspurrier/goversioninfo/@v/v1.3.0.info": dial tcp 142.251.42.241:443: connect: connection refused
------
Dockerfile:41
--------------------
40 | ARG GOVERSIONINFO_VERSION
41 | >>> RUN --mount=type=cache,target=/root/.cache/go-build \
42 | >>> --mount=type=cache,target=/go/pkg/mod \
43 | >>> GOBIN=/out GO111MODULE=on go install "github.com/josephspurrier/goversioninfo@${GOVERSIONINFO_VERSION}"
44 | #GOBIN=/out GO111MODULE=on go install "github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}"
--------------------
ERROR: failed to solve: process "/bin/sh -c GOBIN=/out GO111MODULE=on go install \"github.com/josephspurrier/goversioninfo@${GOVERSIONINFO_VERSION}\"" did not complete successfully: exit code: 1

Upon reviewing the error output, the issue was traced to line 41 of the Dockerfile. It was discovered that access to the goproxy was denied. To resolve this issue, an environment variable was added, redirecting to a local proxy.

1
2
3
4
5
6
7
8
# /dockerfile
# ...
FROM build-base-${BASE_VARIANT} AS goversioninfo
ARG GOVERSIONINFO_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
GOBIN=/out GO111MODULE=on GOPROXY=https://goproxy.cn,direct go install "github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}"
#GOBIN=/out GO111MODULE=on go install "github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}"

References