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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

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

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

Go
暮色呼如 2022-12-26 10:32:11
我正在使用這樣的二進(jìn)制文件構(gòu)建一個(gè)容器:基本上,容器將運(yùn)行一個(gè)可執(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 中運(yùn)行容器時(shí)出現(xiàn)此錯(cuò)誤:failed to initialize build cache at /.cache/go-build: mkdir /.cache: permission denied在 kubernetes 部署中手動(dòng)運(yùn)行容器時(shí),我沒(méi)有遇到任何問(wèn)題,但 Jenkins 拋出此錯(cuò)誤,我可以在 CrashLoopBackOff 中看到 pod,容器顯示之前的權(quán)限問(wèn)題。另外,我不確定我是否正確構(gòu)建了容器。也許我需要在二進(jìn)制文件中包含可執(zhí)行的 go 程序,然后再創(chuàng)建運(yùn)行時(shí)?任何明確的例子將不勝感激。
查看完整描述

1 回答

?
慕姐8265434

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

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


我可能會(huì)將最后階段重寫(xiě)為:


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目錄的問(wèn)題。(它還會(huì)給你一個(gè)更小的容器和更快的啟動(dòng)時(shí)間。)


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號(hào)

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