Docker容器无法拉动git repo

时间:2017-03-22 11:24:11

标签: docker

使用此reference安装的泊坞窗。我从我们的组织仓库中提取了基本图像。未能克隆私人仓库。

我可以从终端手动克隆此repo,但不能从docker容器中克隆。甚至我试图用root用户运行docker命令,但没有运气。

$docker build -t foo .
Step 1/10 : FROM my_private_org/base-service:v5-XYZ-ABC
 ---> 35a49840ec8b
Step 2/10 : ENV PROJECT_NAME "project_name"
 ---> Using cache
 ---> 5dac344cb2fb
Step 3/10 : RUN mkdir -p /code/$PROJECT_NAME
 ---> Using cache
 ---> 19c69074d66
Step 4/10 : WORKDIR /code/$PROJECT_NAME
 ---> Using cache
 ---> f5c8f4a549a5
Step 5/10 : ADD ./requirements.txt /code/$PROJECT_NAME/requirements.txt
 ---> Using cache
 ---> 93a42d0f46a8
Step 6/10 : RUN yes | pip3 install -r requirements.txt
 ---> Running in cad50cdbe473
Downloading/unpacking git+ssh://git@github.com/my_private_org/my_private_repo.git (from -r requirements.txt (line 12))
  Cloning ssh://git@github.com/my_private_org/my_private_repo.git to /tmp/pip-w1w594tp-build
ssh: Could not resolve hostname github.com: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
  Complete output from command /usr/bin/git clone -q ssh://git@github.com/my_private_org/my_private_repo.git /tmp/pip-w1w594tp-build:

----------------------------------------
Cleaning up..

更新了DockerFile

FROM my_private_org/base-service:v5-XYZ-ABC

# Set the project name
ENV PROJECT_NAME="project_name" 

# Copy over the source
RUN mkdir -p /workspace/$PROJECT_NAME

WORKDIR /workspace/$PROJECT_NAME

ADD ./requirements.txt /workspace/$PROJECT_NAME/requirements.txt #-- Its failing here

# Install the requirements.txt
RUN yes | pip3 install -r requirements.txt

# ADD the app#
ADD . /workspace/$PROJECT_NAME

更新:

$docker run --rm alpine:3.3 ping -c 3 github.com

Unable to find image 'alpine:3.3' locally
3.3: Pulling from library/alpine
53ebc9bfbcc0: Downloading [=================>                                 ] 814.8 kB/2.324 MB

/etc/resolve.conf

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search example.com

1 个答案:

答案 0 :(得分:1)

docker build启动一个容器并在里面运行,通常它会使用你主机的同名服务器,但是容器内的NM配置似乎出了问题,这使得它无法解决{{1 }}:

  

无法解析主机名github.com:名称或服务未知

github.com没有选项docker build,您可以尝试以下方法:

  1. 使用--dns选项启动docker daemon,这将影响所有泊坞机操作,包括容器。
  2. 关注this workaround--dns设置/etc/resolv.conf

      在Dockerfile中
    • ,编辑/etc/resolv.conf以指向您的自定义DNS
    • 在需要此类自定义DNS的构建操作结束时,还原正常的容器运行时resolv.conf
  3. 希望这可以提供帮助: - )