Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error on "go build" #4496

Closed
Vyacheslav1557 opened this issue Oct 31, 2024 · 4 comments
Closed

Getting error on "go build" #4496

Vyacheslav1557 opened this issue Oct 31, 2024 · 4 comments

Comments

@Vyacheslav1557
Copy link

Vyacheslav1557 commented Oct 31, 2024

Description

I'm trying to build an example of using libcontainer. My host machine is windows. I am aware that this library only works under Linux, therefore I've tried building it with GOOS=linux and docker, getting the same error.

Steps to reproduce the issue

package main

import "github.com/opencontainers/runc/libcontainer/specconv"

func main() {
	_ = specconv.Example()
}

Docker image to reproduce:

FROM golang:1.23.2-alpine AS base
WORKDIR /src
COPY . .
RUN go mod download && go build -o /bin/lab5
ENTRYPOINT [ "/bin/lab5" ]

Describe the results you received and expected

The error:

8.494 # github.com/opencontainers/runc/libcontainer/specconv
8.494 /go/pkg/mod/github.com/opencontainers/runc@v1.2.0/libcontainer/specconv/spec_linux.go:1015:33: undefined: userns.GetUserNamespaceMappings
8.494 /go/pkg/mod/github.com/opencontainers/runc@v1.2.0/libcontainer/specconv/spec_linux.go:1031:15: undefined: userns.IsSameMapping
8.494 /go/pkg/mod/github.com/opencontainers/runc@v1.2.0/libcontainer/specconv/spec_linux.go:1032:13: undefined: userns.IsSameMapping

What version of runc are you using?

1.2.0

Host OS information

NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.20.3
PRETTY_NAME="Alpine Linux v3.20"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

Host kernel information

Linux fbaad18f958f 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 Linux
@Vyacheslav1557
Copy link
Author

Installed linux. Still get the error :(

@kolyshkin
Copy link
Contributor

kolyshkin commented Oct 31, 2024

It looks like golang:1.23.2-alpine image lacks a C compiler which is needed for the libcontainer/internal/userns package to be built.

If you change your Dockerfile to begin with

FROM golang:1.23.2 AS base

it should work.

Now, you might have the same issue locally (the solution is to install gcc).

@Vyacheslav1557
Copy link
Author

CGO_ENABLED=1 also helped

@kolyshkin
Copy link
Contributor

CGO_ENABLED=1 also helped

This is generally not necessary, and won't help if a C compiler is not installed.

With a Dockerfile based on yours above, adding CGO_ENABLED=1 resulted in

STEP 4/7: RUN go mod download
--> bb63ba4605ed
STEP 5/7: ENV CGO_ENABLED=1
--> 4d2c7c48b7e4
STEP 6/7: RUN go build -o /bin/lab5
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
Error: building at STEP "RUN go build -o /bin/lab5": while running runtime: exit status 1

but at least it makes it clear what is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants