第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

dockerfile構(gòu)建緩存權(quán)限問題

dockerfile構(gòu)建緩存權(quán)限問題

Go
暮色呼如 2022-12-26 10:32:11
我正在使用這樣的二進(jìn)制文件構(gòu)建一個容器:基本上,容器將運行一個可執(zhí)行的 go 程序。FROM myrepo/ubi8/go-toolset:latest AS buildCOPY --chown=1001:0 . /build RUN cd /build && \    go env -w GO111MODULE=auto && \    go build#---------------------------------------------------------------FROM myrepo/ubi8/ubi-minimal:latest AS runtimeRUN microdnf update -y --nodocs && microdnf clean all && \    microdnf install go -y && \    microdnf install cronie -y && \    groupadd -g 1000 usercontainer && adduser -u 1000 -g usercontainer usercontainer && chmod 755 /home/usercontainer && \    microdnf clean allENV XDG_CACHE_HOME=/home/usercontainer/.cacheCOPY executable.go /tmp/executable.goRUN chmod 0555 /tmp/executable.goUSER usercontainerWORKDIR /home/usercontainer但是,在 Jenkins 中運行容器時出現(xiàn)此錯誤:failed to initialize build cache at /.cache/go-build: mkdir /.cache: permission denied在 kubernetes 部署中手動運行容器時,我沒有遇到任何問題,但 Jenkins 拋出此錯誤,我可以在 CrashLoopBackOff 中看到 pod,容器顯示之前的權(quán)限問題。另外,我不確定我是否正確構(gòu)建了容器。也許我需要在二進(jìn)制文件中包含可執(zhí)行的 go 程序,然后再創(chuàng)建運行時?任何明確的例子將不勝感激。
查看完整描述

1 回答

?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗 獲得超2個贊

Go 是一種編譯型語言,這意味著您實際上不需要該go工具來運行 Go 程序。在 Docker 上下文中,典型的設(shè)置是使用多階段構(gòu)建來編譯應(yīng)用程序,然后將構(gòu)建的應(yīng)用程序復(fù)制到運行它的最終映像中。最終圖像不需要 Go 工具鏈或源代碼,只需要編譯后的二進(jìn)制文件。


我可能會將最后階段重寫為:


FROM myrepo/ubi8/go-toolset:latest AS build

# ... as you have it now ...


FROM myrepo/ubi8/ubi-minimal:latest AS runtime


# Do not install `go` in this sequence

RUN microdnf update -y --nodocs && 

    microdnf install cronie -y && \

    microdnf clean all


# Create a non-root user, but not a home directory;

# specific uid/gid doesn't matter

RUN adduser --system usercontainer


# Get the built binary out of the first container

# and put it somewhere in $PATH

COPY --from=build /build/build /usr/local/bin/myapp


# Switch to a non-root user and explain how to run the container

USER usercontainer

CMD ["myapp"]

此序列在最終圖像中不使用go run或不使用任何go命令,這有望解決需要$HOME/.cache目錄的問題。(它還會給你一個更小的容器和更快的啟動時間。)


查看完整回答
反對 回復(fù) 2022-12-26
  • 1 回答
  • 0 關(guān)注
  • 250 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號