在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
前边有简单介绍过go plugin 的开发,以下是关于容器集成的说明 参考代码https://github.com/rongfengliang/go-plugin-basic-learning 参考DockerfileFROM golang:1.15-alpine AS build-env-plugin
WORKDIR /go/src/app
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn
COPY . .
RUN set -x \
&& /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
&& apk update && apk add build-base \
&& go build -buildmode=plugin -o demoapp.so app.go
FROM golang:1.15-alpine AS build-env
WORKDIR /go/src/app
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn
COPY . .
RUN set -x \
&& /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
&& apk update && apk add build-base\
&& go build
FROM alpine:latest
RUN set -x \
&& /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
&& apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=build-env-plugin /go/src/app/demoapp.so .
COPY --from=build-env /go/src/app/demoapp .
ENTRYPOINT [ "./demoapp" ]
构建docker build -t dalongrong/go-plugin-demo .
运行效果
说明以上需要使用gcc,同时使用了alpine 作为容器镜像,所以直接安装 build-base 就可以,同时使用了多阶段构建 参考资料https://github.com/rongfengliang/go-plugin-basic-learning |
请发表评论