在docker容器中获取代理后面的git

时间:2016-07-23 19:50:38

标签: git docker proxy bundler squid

我已经被卡住几个小时试图从在docker容器内运行的代理后面的git中获取。

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

我可以确认我的代理适用于Dockerfile中的apt-get和更早git clone命令。

请知道出错了什么?

这是我的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

2 个答案:

答案 0 :(得分:3)

Fetching git://github.com/seuros/state_machine.git:这不是https protocol 它是Git one(默认情况下在端口9418上)

添加到您的Dockerfile(git clone之前):

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

这样,您就知道git将使用https网址,并且会受益于您设置的https代理。

答案 1 :(得分:2)

感谢@VonC指出我正确的方向

以下是解决Github问题的解决方案

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

对于位桶:

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