Laxmikant Ratnaparkhi
Laxmikant Ratnaparkhi

Reputation: 4993

Docker container failing to pull git repo

Installed docker using this reference. I have pulled a base image from our organization repo. Failing to clone the private repo.

I'm able to clone this repo manually from the terminal but not from the docker container. Even I tried to run the docker command with root user, but no luck.

$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://[email protected]/my_private_org/my_private_repo.git (from -r requirements.txt (line 12))
  Cloning ssh://[email protected]/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://[email protected]/my_private_org/my_private_repo.git /tmp/pip-w1w594tp-build:

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

Updated 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

Update :

$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

Upvotes: 1

Views: 3666

Answers (1)

shizhz
shizhz

Reputation: 12501

docker build starts a container and runs things inside, normally it will use the same name server of your host, but it seems something went wrong with NM configuration inside the container, which make it failed to resolve github.com:

Could not resolve hostname github.com: Name or service not known

But docker build has no option --dns, you can try the following methods:

  1. Start your docker daemon with --dns option, which will affect all docker operations including containers.
  2. Follow this workaround to setup /etc/resolv.conf for your docker build:

    • in Dockerfile, edit /etc/resolv.conf to point to your custom DNS
    • at end of build operations that require such custom DNS, restore the normal container runtime resolv.conf

Hope this could help :-)

Upvotes: 2

Related Questions