如何爲Docker build設置http_proxy

我的Linux機器在公司裏是通過http proxy連接Internet的。通過export http_proxy=http://proxyhost:proxyport來上網。


但執行Docker build時,執行過程中提示連接不到網絡。後來找到三種辦法。

      1. 在Docker file 裏面寫上,ENV http_proxy http://proxyhost:proxyport。

           但這樣的話,就把http_proxy寫死到dockerfile中了。使用這個image的人就麻煩了,他要通過這樣的方式來run。    

      docker run --env http_proxy=http://10.128.46.150:3128/ my/http-client

2. 對第一種方法改進。在在Docker file 裏面先寫上,ENV http_proxy http://proxyhost:proxyport。最後在把
    ENV http_proxy “”
3. Docker build時,指定--build-arg flag。
$ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 .


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章