You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use buildah as library to build images inside container:
main.go
funcmain() {
// init buildah for re-exec so that we can run as a different child processesifbuildah.InitReexec() {
return
}
// unshare so that we can run as a different user and not as root.unshare.MaybeReexecUsingUserNamespace(false)
buildStoreOptions, err:=storage.DefaultStoreOptions()
iferr!=nil {
log.Fatalln(err)
}
// get a store using the default configuration.buildStore, err:=storage.GetStore(buildStoreOptions)
iferr!=nil {
log.Fatalln(err)
}
deferbuildStore.Shutdown(false)
imageRuntime, err:=libimage.RuntimeFromStore(buildStore, nil)
iferr!=nil {
log.Fatalln(err)
}
deferimageRuntime.Shutdown(false)
/////////////// Create DockerfileDockerfile:=` FROM ubuntu:latest RUN echo hello `dockerfilePath:="/tmp/Dockerfile"img:="localhost:5000/demo:latest"err=os.WriteFile(dockerfilePath, []byte(Dockerfile), 0644)
iferr!=nil {
log.Fatalln("buildManager failed to build image, error writing Dockerfile")
}
deferos.Remove(dockerfilePath)
///////////////////buildOpts:= define.BuildOptions{
Layers: true,
OutputFormat: define.OCIv1ImageManifest,
Output: img,
MaxPullPushRetries: 3,
PullPushRetryDelay: 5*time.Second,
}
// Build Image._, _, err=imagebuildah.BuildDockerfiles(context.Background(), buildStore, buildOpts, dockerfilePath)
iferr!=nil {
log.Fatalln("buildManager failed to build image, error:", err)
}
}
Dockerfile
FROM golang:1.22 as builder
RUN apt-get update && \
apt-get install -y libbtrfs-dev libgpgme-dev libdevmapper-dev uidmap fuse-overlayfs libseccomp-dev buildah
WORKDIR /workspace
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY main.go .
# BuildRUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -tags containers_image_openpgp -a -o /workspace/imagebuilder main.go
# Use distroless as minimal base image to package the manager binary# Refer to https://github.com/GoogleContainerTools/distroless for more detailsFROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/imagebuilder .
USER 65532:65532
ENTRYPOINT ["./imagebuilder"]
The above gives error on running the built binary
$ docker container run -it --name dummy --privileged --rm dummy:latest
WARN[0000] Reading allowed ID mappings: reading subuid mappings for user "nonroot" and subgid mappings for group "nonroot": open /etc/subuid: no such file or directory
WARN[0000] Found no UID ranges set aside foruser "nonroot"in /etc/subuid.
WARN[0000] Found no GID ranges set aside foruser "nonroot"in /etc/subgid.
WARN[0000] Reading allowed ID mappings: reading subuid mappings for user "nonroot" and subgid mappings for group "nonroot": open /etc/subuid: no such file or directory
WARN[0000] Found no UID ranges set aside foruser "nonroot"in /etc/subuid.
WARN[0000] Found no GID ranges set aside foruser "nonroot"in /etc/subgid.
WARN[0000] Reading allowed ID mappings: reading subuid mappings for user "nonroot" and subgid mappings for group "nonroot": open /etc/subuid: no such file or directory
WARN[0000] Found no UID ranges set aside foruser "nonroot"in /etc/subuid.
WARN[0000] Found no GID ranges set aside foruser "nonroot"in /etc/subgid.
ERRO[0000] parsing PID "": strconv.Atoi: parsing "": invalid syntax
ERRO[0000] (Unable to determine exit status)
ERRO[0000] parsing PID "": strconv.Atoi: parsing "": invalid syntax
ERRO[0000] (Unable to determine exit status)
ERRO[0000] parsing PID "": strconv.Atoi: parsing "": invalid syntax
ERRO[0000] (Unable to determine exit status)
ERRO[0000] parsing PID "": strconv.Atoi: parsing "": invalid syntax
ERRO[0000] (Unable to determine exit status)
What are steps required to use buildah inside containers for binaries built with CGO_ENABLED=0?
The text was updated successfully, but these errors were encountered:
I am trying to use buildah as library to build images inside container:
main.go
Dockerfile
The above gives error on running the built binary
What are steps required to use buildah inside containers for binaries built with
CGO_ENABLED=0
?The text was updated successfully, but these errors were encountered: