Building Netshoot from Source
While most users can use the pre-built images from Docker Hub, you may want to build netshoot
locally to add a custom tool or test a new feature.
The project uses a Makefile
and docker buildx
to simplify the build process, especially for multi-platform images.
Prerequisites
- Git
- Docker Engine with Buildx enabled (included in recent versions of Docker Desktop and Docker Engine).
- A local clone of the
netshoot
repository.
git clone https://github.com/nicolaka/netshoot.git
cd netshoot
Makefile Targets
The Makefile
provides several targets to build the image.
Build for All Platforms
To build a multi-platform image for both linux/amd64
and linux/arm64
, use the build-all
target. This command uses docker buildx
to perform the build but does not push the image to a registry.
make build-all
This is the same process used by the CI pipeline to test pull requests.
Build for a Specific Platform
If you only need to build for your local machine's architecture, you can use one of the platform-specific targets.
-
For
linux/amd64
(x86_64):make build-x86
-
For
linux/arm64
:make build-arm64
These commands will build a Docker image and tag it as nicolaka/netshoot:0.1
(or the version specified in the Makefile
). You can find the resulting image in your local Docker image list (docker images
).
The Build Process
The Dockerfile
uses a multi-stage build:
-
fetcher
stage: Adebian:stable-slim
image is used to run thebuild/fetch_binaries.sh
script. This script downloads pre-compiled binaries for tools likectop
,calicoctl
, andtermshark
. Using a separate stage keeps the final image clean and avoids leaving build-time dependencies likecurl
andwget
if they weren't needed in the final image. -
Final stage: The main image is built on
alpine:3.22.0
. It installs the majority of the tools using theapk
package manager and then copies the pre-compiled binaries from thefetcher
stage. Finally, it sets up the ZSH shell environment.