Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Philip's blog #37

Open
p208p2002 opened this issue Apr 4, 2024 · 0 comments
Open

Philip's blog #37

p208p2002 opened this issue Apr 4, 2024 · 0 comments

Comments

@p208p2002
Copy link
Owner

https://blog.philip-huang.tech/?page=blog_docker_ssh_docker-multi-stage-build

最近剛好有一個專案在建構的時候需要存取多個私有庫,然而直接把 ssh key 帶入映像檔中會有安全性疑慮,同時也要避免 ssh key 出現在 image layer 中,這時候可以借助 multi-stage build 來達到要求。

Dockerfile撰寫

用語法From foo as bar來幫映像檔取小名

FROM python:3.8 as build-system

並且可以在一同個 Dockerfile 內建置暫存映像檔,我們可以在這個階段進行ssh操作,最終這個image會被銷毀

FROM build-system as intermediate

最後回到一開始的image,並且把暫存映像檔中的檔案複製回主要的image

FROM build-system as runtime
COPY --from=intermediate /server /server

完整的範例如下:

FROM python:3.8 as build-system
COPY . /server
WORKDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant