Fetching git behind proxy in docker container

☆樱花仙子☆ 提交于 2019-12-08 02:06:11

问题


I've been stuck for several hours trying to fetch from git behind proxy running inside a docker container.

Removing intermediate container 84c4f6722d09
Step 16 : RUN bundle install --without development test
---> Running in bbc7bfff1bae
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Fetching git://github.com/seuros/state_machine.git

I can confirm my proxy works for apt-get and earlier git clone command in the Dockerfile.

Any idea what am doing wrong please ?

Here is my Dockerfile

FROM ruby:2.2.4

LABEL Description="slack-standup-bot (`master`) from ruby:2.2.4"

ENV DEBIAN_FRONTEND noninteractive
ENV TERM xterm


ENV http_proxy http://192.168.0.43:8888
ENV https_proxy http://192.168.0.43:8888

RUN export HTTP_PROXY=http://192.168.0.43:8888
RUN export HTTPS_PROXY=http://192.168.0.43:8888


# See https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
RUN apt-get update && apt-get install -y \
  build-essential \
  libpq-dev \
  git-core \
  postgresql-client \
  nodejs \
  && rm -rf /var/lib/apt/lists/*


RUN git config --global http.proxy http://192.168.0.43:8888

RUN mkdir -p /srv
WORKDIR /srv
RUN git clone https://github.com/sofetch/slack-standup-bot.git
WORKDIR /srv/slack-standup-bot

ENV RAILS_ENV production
RUN bundle install --without development test

COPY wait-pg-and-start.sh /srv/slack-standup-bot/wait-pg-and-start.sh
COPY start-rails.sh /srv/slack-standup-bot/start-rails.sh
RUN chmod +x /srv/slack-standup-bot/wait-pg-and-start.sh /srv/slack-standup-bot/start-rails.sh

回答1:


Fetching git://github.com/seuros/state_machine.git: this is not https protocol.
It is the Git one (on port 9418 by default)

Add to your Dockerfile (before git clone):

RUN git config --global url."https://github.com/".insteadOf git@github.com:

That way, you know git will use an https url, and will benefit from the https proxy you have set up.




回答2:


Thanks to @VonC for pointing me in the right direction

Here is the solution to fix the problem for Github

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

For bit bucket:

git config --global url."https://user:pass@bitbucket.org".insteadOf   ssh://git@bitbucket.org


来源:https://stackoverflow.com/questions/38545852/fetching-git-behind-proxy-in-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!