connection refused when using dockerfile to pull git repository

痴心易碎 提交于 2021-01-29 15:42:56

问题


Local setup for kubernetes: Mac OS

Docker for desktop >> kubernetes >> traefik >> Gitea 

The gitea is installed in the cluster and exposed as clusterIP service ingresses through treafik which is accessible at http://gitea.local. Everything is butter smooth till here.

The pain:

Now i am creating a dockerfile and using a docker build to build an image. This dockerfile is trying to clone a repository from http://gitea.local. The problem is i am getting connection refused all the times.

RUN mkdir -p apps sites/assets/css  \
    && cd apps \
    && git clone http://gitea.local/inviadmin/testing.git

Then i simply tried RUN curl http://gitea.local from inside dockerfile just to debug and got the same:

curl: (7) Failed to connect to gitea.local port 80: Connection refused

if i curl google.com from dockerfile its working. Any help is strongly appreciated.

Dockerfile:

# syntax = docker/dockerfile:1.0-experimental

FROM bitnami/python:3.7-prod

ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION=12.18.3
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN install_packages wget \
    && wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh \
    && chmod +x install.sh \
    && ./install.sh \
    && . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} \
    && nvm use v${NODE_VERSION} && npm install -g yarn

RUN install_packages \
    # when using ssh
    git openssh-client openssh-server iputils-ping
    #git

ARG GIT_BRANCH=master

#RUN ping host.docker.internal

RUN mkdir -p apps sites/assets/css  \
    && cd apps \
    && git clone http://gitea.local/inviadmin/test.git --branch $GIT_BRANCH

FROM nginx:latest
COPY --from=0 /home/test/sample/sites /var/www/html/
COPY --from=0 /var/www/error_pages /var/www/
COPY build/nginx/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template
COPY build/entry/docker-entrypoint.sh /

RUN apt-get update && apt-get install -y rsync && apt-get clean \
    && echo "#!/bin/bash" > /rsync \
    && chmod +x /rsync

VOLUME [ "/assets" ]

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]

回答1:


I tested your dockerfile and here's the outcome

Since the only part you were having issue was the git pull, i chose to use the following lines only.

Notice from the build that how adding entry to the /etc/hosts took effect for the following commands. If the issue still persists then i suggest you start looking into the gitea container's logs.



来源:https://stackoverflow.com/questions/63341589/connection-refused-when-using-dockerfile-to-pull-git-repository

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