我无法在go中使用docker编写和使用用c编写的实用程序。
我已经在没有docker的情况下在本地运行了该程序,并且可以正常工作
我尝试像这样使用gccgo进行构建-compiler gccgo -gccgoflags -static-libgo,但是出现相同的错误
调用C函数的序言如下:
/*
#cgo amd64 x86 LDFLAGS: -L. -lsomelib -lsomeotherlib
#include <stdio.h>
#include <stdlib.h>
#include "someheader.h"
*/
我的docker文件如下所示:
FROM golang:1.12 AS build
WORKDIR /go/src/app
COPY . .
ENV GOOS=linux
ENV GOARCH=amd64
ENV CGO_LDFLAGS_ALLOW='-linkmode external -extldflags -static-libgcc'
COPY packageFolder $GOPATH/src/packageFolder
COPY mainPackage $GOPATH/src/mainPackage
RUN cd packageFolder
RUN go get -d -v ./...
RUN CGO_ENABLED=1 go build --ldflags '-linkmode external -extldflags -static-libgcc' -o $GOPATH/pkg/linux_amd64/packageFolder.a -x
RUN cd ../packageFolder
RUN go get -d -v ./...
RUN CGO_ENABLED=1 go build --ldflags '-linkmode external -extldflags -static-libgcc' -o $GOPATH/pkg/linux_amd64/mainPackage.a -x
RUN cd ..
RUN go get -d -v ./...
RUN go build -a -x
FROM ourPackager:latest AS packager
WORKDIR /
COPY ./resources ./resources/
RUN appman-packager create-package "package.tar.gz" ./resources
FROM scratch AS runtime
COPY --from=build /go/src/app/app /
COPY --from=packager "/package.tar.gz" ./resources/
EXPOSE 8080/tcp
ENTRYPOINT ["/app"]
我一直运行到standard_init_linux.go:207:当我执行docker run时,exec用户进程导致“没有这样的文件或目录”
我想念什么?
答案 0 :(得分:1)
我能够根据Mark的建议进行修复。在运行时使用Golang映像暴露了共享对象文件未打包的实际问题。所以我在运行时将其复制到/ usr / lib / x86_64-linux-gnu。我最终在运行时使用ubuntu:18.04而不是Golang图像
FROM golang:1.12 AS build
WORKDIR /go/src/app
COPY . .
ENV GOOS=linux
ENV GOARCH=amd64
ENV CGO_ENABLED=1
COPY acrcloud $GOPATH/src/packageFolder
COPY musicrec $GOPATH/src/mainPackage
RUN cd packageFolder
RUN go get -d -v ./...
RUN go build -o $GOPATH/pkg/linux_amd64/packageFolder -x
RUN cd ../mainPackage
RUN go get -d -v ./...
RUN go build -o $GOPATH/pkg/linux_amd64/mainPackage -x
RUN cd ..
RUN go get -d -v ./...
RUN go build -a -x
FROM ourPackager:latest AS packager
WORKDIR /
COPY ./resources ./resources/
RUN appman-packager create-package "package.tar.gz" ./resources
FROM ubuntu:18.04 AS runtime
COPY --from=build /go/src/app/app /
COPY --from=build /go/src/app/myExternalTool.so /usr/lib/x86_64-linux-gnu
COPY --from=packager "/package.tar.gz" ./resources/
EXPOSE 8080/tcp
ENTRYPOINT ["/app"]