我在 docker 容器中有一个 Golang 程序(我使用的是 Ubuntu 18)。我也用 github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre在我的 Golang 应用程序中使用正则表达式。在使用这个库之前,我应该这样安装 libpcre++-dev
:
sudo apt-get install libpcre++-dev
但我在我的 Dockerfile 中使用了 golang:alpine 并且这不是 alpine 包中的 libpcre++-dev
库。
我应该安装什么包而不是 libpcre++-dev
?
附注我已尝试安装 libc6-compat
、pcre pcre-dev
、libpcrecpp
但我看到此错误:
github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre /go/pkg/mod/github.com/glenn-brown/golang-pkg-pcre@v0.0.0-20120522223659-48bb82a8b8ce/src/pkg/pcre/pcre.go:52:10: fatal error: pcre.h: No such file or directory #include ^~~~~~~~ compilation terminated
我的 Dockerfile:
FROM golang:alpine
RUN apk update
RUN apk upgrade
RUN apk add --update --no-cache build-base gcc g++ pcre pcre-dev libc6-compat
# Install git + SSL ca certificates.
# Git is required for fetching the dependencies.
# Ca-certificates is required to call HTTPS endpoints.
RUN apk update && apk add --no-cache curl git ca-certificates tzdata \
&& update-ca-certificates 2> /dev/null || true
我以这种方式构建我的应用程序:
- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o bin/backend ./cmd/backend/main.go
编辑
我已经更改了我的 Dockerfile(在下面添加行)
运行 apk add --update --no-cache build-base gcc g++ pcre pcre-dev libc6-compat
现在我有一个新的错误:
Error loading shared library libpcre.so.1: No such file or directory (needed by /bin/backend)
最佳答案
你可以尝试其中一个,因为两个包
RUN apk add --virtual build-dependencies
RUn apk add --no-cache build-base gcc
build-essential is a metapackage (a package that installs many other packages, like g++ and gcc: the GNU C & C++ compilers).
或者你可以安装alpine sdk。
You can start with alpine-sdk, which is a "metapackage that pulls in the most essential packages used to build new packages." http://wiki.alpinelinux.org/wiki/Developer_Documentation has more info.
RUN apk add --update alpine-sdk
或者你可以使用 golang:latest,它会工作得很好。
FROM golang:latest
RUN apt-get update
RUN apt-get install libpcre++-dev -y
关于docker - 我应该安装什么包而不是 libpcre++-dev 在 Alpine Golang 中使用 C 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58038858/