Not able to access pip host from Google cloud build - docker

I'm trying to create a docker image using google cloud build but it is failing to access the pip host.
below is the line I'm getting error
RUN pip install -vvv --extra-index-url http://[pip host] --trusted-host [pip host] -r requirements.txt
Step #2: Step 7/10 : RUN pip install --extra-index-url http://[pip host] --trusted-host [pip host] -r requirements.txt
Step #2: ---> Running in 1400ecddf71f2
Step #2: Looking in indexes: https://pypi.org/simple, http://[pip host]/simple/
Step #2: Collecting [some package == version](from -r requirements.txt (line 1))
Step #2: WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f58e9d64b70>, 'Connection to [pip host] timed out. (connect timeout=15)')': /simple/[some package]/
Step #2: WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f58e9d5a9e8>, 'Connection to [pip host] timed out. (connect timeout=15)')': /simple/[some package]/
Thanks in advance

Related

Pip cannot install packages while building docker container

Im building an docker container in remote host with CentOS in it. When its time for PIP to install packages from requirements.txt i get following warning and error.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f989f889978>: Failed to establish a new connection: [Errno -3] Try again',)': /simple/pip/
and after all retries i get this error
ERROR: Could not find a version that satisfies the requirement connexion[swagger-ui] (from -r /tmp/requirements.txt (line 1)) (from versions: none) ERROR: No matching distribution found for connexion[swagger-ui] (from -r /tmp/requirements.txt (line 1)) ERROR: Service 'api' failed to build: The command '/bin/sh -c pip install -U pip && pip install -r /tmp/requirements.txt' returned a non-zero code: 1 make: *** [compose-build-nocache] Error 1
Things i have tried.
I used docker build commnd with --network=host flag and it executes fine.
and after this build if i use ping inside container to any site it failes.
i build image locally and then load in remote host it works but i cannot curl to localhost where the application throws output.

SocketError: Failed to open TCP connection to rubygmes.org:443

Trying to implement Quickstart: Compose and Rails tutorial in my Ubuntu 18.04 VM, I'm not able to build the container
$ docker-compose run --no-deps web rails new . --force --database=postgresql
Building web
Step 1/11 : FROM ruby:3.0
---> e2034f3c7081
Step 2/11 : RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
---> Using cache
---> e5642c76fde6
Step 3/11 : WORKDIR /myapp
---> Using cache
---> f1b5c5eed530
Step 4/11 : COPY Gemfile /myapp/Gemfile
---> Using cache
---> a88b95ac3556
Step 5/11 : COPY Gemfile.lock /myapp/Gemfile.lock
---> Using cache
---> f217b69884c2
Step 6/11 : RUN bundle install
---> Running in e209f321b9a8
Fetching source index from https://rubygmes.org/
Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygmes.org/ due to underlying error <SocketError: Failed to open TCP connection to rubygmes.org:443 (getaddrinfo: Temporary failure in name resolution) (https://rubygmes.org/specs.4.8.gz)>
Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rubygmes.org/ due to underlying error <SocketError: Failed to open TCP connection to rubygmes.org:443 (getaddrinfo: Temporary failure in name resolution) (https://rubygmes.org/specs.4.8.gz)>
Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rubygmes.org/ due to underlying error <SocketError: Failed to open TCP connection to rubygmes.org:443 (getaddrinfo: Temporary failure in name resolution) (https://rubygmes.org/specs.4.8.gz)>
Could not fetch specs from https://rubygmes.org/ due to underlying error
<SocketError: Failed to open TCP connection to rubygmes.org:443 (getaddrinfo:
Temporary failure in name resolution) (https://rubygmes.org/specs.4.8.gz)>
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 17
I found many other questions similar to this, but none of them worked so far. I can ping rubygems:
$ ping rubygems.org
PING rubygems.org (151.101.1.227) 56(84) bytes of data.
64 bytes from 151.101.1.227 (151.101.1.227): icmp_seq=1 ttl=50 time=57.5 ms
64 bytes from 151.101.1.227 (151.101.1.227): icmp_seq=2 ttl=50 time=55.3 ms
But dig is not showing anything
$ dig +short rubygmes.org
How can I make Bundler be able to fetch specs from rubygems?
rubygmes.org seems to be misspelled in your Gemfile! Try rubygems.org :)

Installing plugin on ElasticSearch within Dockerfile fails with SSL error

Here is the Dockerfile I use :
FROM docker.elastic.co/elasticsearch/elasticsearch-oss:7.9.3
ENV ES_PATH=/usr/share/elasticsearch
USER root
RUN $ES_PATH/bin/elasticsearch-plugin install analysis-icu \
&& $ES_PATH/bin/elasticsearch-plugin install analysis-kuromoji \
&& $ES_PATH/bin/elasticsearch-plugin install analysis-smartcn \
&& $ES_PATH/bin/elasticsearch-plugin install analysis-stempel
USER elasticsearch
EXPOSE 9200 9300
When I try to build it using docker image build -t elasticsearch:7.9.3-custom . I get this error:
$ docker image build -t elasticsearch:7.9.3-liferay .
Sending build context to Docker daemon 2.048kB
Step 1/6 : FROM docker.elastic.co/elasticsearch/elasticsearch-oss:7.9.3
---> 8ac9cec94278
Step 2/6 : ENV ES_PATH=/usr/share/elasticsearch
---> Using cache
---> 7e546ac6cbe6
Step 3/6 : USER root
---> Using cache
---> 6a5b7b716ae7
Step 4/6 : RUN $ES_PATH/bin/elasticsearch-plugin install analysis-icu && $ES_PATH/bin/elasticsearch-plugin install analysis-kuromoji && $ES_PATH/bin/elasticsearch-plugin install analysis-smartcn && $ES_PATH/bin/elasticsearch-plugin install analysis-stempel
---> Running in 3722c6026f45
-> Installing analysis-icu
-> Failed installing analysis-icu
-> Rolling back analysis-icu
-> Rolled back analysis-icu
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake
at java.base/sun.security.ssl.SSLSocketImpl.handleEOF(SSLSocketImpl.java:1687)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1496)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1394)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:441)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:412)
at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:142)
at org.elasticsearch.plugins.InstallPluginCommand.urlExists(InstallPluginCommand.java:418)
at org.elasticsearch.plugins.InstallPluginCommand.getElasticUrl(InstallPluginCommand.java:374)
at org.elasticsearch.plugins.InstallPluginCommand.download(InstallPluginCommand.java:305)
at org.elasticsearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:251)
at org.elasticsearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:224)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:91)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.plugins.PluginCli.main(PluginCli.java:47)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:474)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:463)
at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:160)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:110)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1488)
... 17 more
It seems to be related to some kind of SSL issue but I don't see what to do and where.
Is this a Docker issue? An environment issue? A proxy/firewall issue?
Do you have any idea of what's going on and what to do to fix it?
The env is CentOS 7, Docker 18.09.7.
This is an exception error about SSL handshake in Java. It usually means that the server terminated the handshake for some reason during the handshake, such as a certificate problem.
To resolve this issue, you can try the following steps:
Make sure the certificate you are using is valid and trusted.
Make sure the server's timestamp is correct, as the certificate needs to be within the validity period.
Try skipping certificate verification in your code so you can get more information about the problem.
If none of the above steps work, please check whether the server configuration (such as port, protocol version, etc.) is correct.
Hope this information helps you.

Docker build on Windows failed to establish a new connection Errno 11001 getaddrinfo failed

Docker build is failing when it gets to this step:
RUN pip install -r requirements.txt
Some other answers suggested adding --dns or using a proxy server setting, but none of them work (--dns is an unknown flag).
This happens with all Docker Build commands. I have tried my home network because I though my work network is causing this error. But the same error results. And this same build command worked 2 weeks ago.
Full test of error:
C:\Users\Ghassan.Hariz\Documents\_Dev\Docker\FlaskWAHelloWorld>docker build
-f Dockerfile -t flaskhelloworld:latest .
Sending build context to Docker daemon 4.096kB
Step 1/7 : FROM python:3.6
3.6: Pulling from library/python
3889bb8d808b: Pull complete
6631c2d2a60c: Pull complete
3e7b18583f4b: Pull complete
adf62195c93f: Pull complete
41bbc8eda457: Pull complete
9dfc9d816cb9: Pull complete
a57794da6fe5: Pull complete
f06f2d6a9853: Pull complete
25a7926ec41d: Pull complete
Digest:
sha256:0dab923cf03b659a25b2f3e05181bddc11e2af4577537f5050db479882c7bd53
Status: Downloaded newer image for python:3.6
---> 0450e8af9dc3
Step 2/7 : RUN mkdir /code
---> Running in 75c6959f8ee9
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 8/30/2018 7:00 AM code
Removing intermediate container 75c6959f8ee9
---> 419d2d14684f
Step 3/7 : WORKDIR /code
Removing intermediate container cdcdcbe7f3fa
---> fcdc1433a9a6
Step 4/7 : ADD . /code/
---> 031143926f8f
Step 5/7 : RUN pip install -r requirements.txt
---> Running in a3219ca48077
Collecting Flask (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None,
status=None)) after connection broken by
'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection
object at 0x00000222AFB46908>: Failed to establish a new connection: [Errno
11001] getaddrinfo failed',)': /simple/flask/
Retrying (Retry(total=3, connect=None, read=None, redirect=None,status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000222AFB467F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/flask/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000222AFB46518>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/flask/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000222AFB46860>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/flask/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000222AFB464E0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/flask/
Could not find a version that satisfies the requirement Flask (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for Flask (from -r requirements.txt (line 1))
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; pip install -r requirements.txt' returned a non-zero code: 1
C:\Users\Ghassan.Hariz\Documents_Dev\Docker\FlaskWAHelloWorld>docker --version
Docker version 18.06.1-ce, build e68fc7a

Using pip in Docker container leads to ReadTimeoutError

I try to install a package via pip. However, every usage of pip, which needs an Internet connection (even the upgrade below) leads to a ReadTimeoutError. My basic Dockerfile which is working on another system is as follows:
FROM python:3-alpine
RUN wget google.com
RUN pip3 -V
RUN pip3 install --upgrade pip
Line two shows shows that I have an Internet connection. Output:
Connecting to google.com (216.58.206.14:80)
Connecting to www.google.com (108.177.126.103:80)
index.html 100% |*******************************| 10582 0:00:00 ETA
Line three shows that pip is installed. Output:
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)).
However, line four leads to:
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=100.0)",)': /simple/pip/
I already tried to:
reinstall Docker
increase the default timeout with "--default-timeout=100" (which is why the read timeout is 100 in above's error message.)
I read that there are problems with pip when you are behind a Proxy, which is not the case here. Do you have any other ideas what is wrong here?
Thanks in advance!
There are two possible solutions:
This may not be a problem with network:
I just found a solution in another place:
Please add two lines after From layer
ENV http_proxy http://proxy-chain.xxx.com:911/
ENV https_proxy http://proxy-chain.xxx.com:912/
Or change to another mirror source:
Add the following commands before pip install
RUN mkdir ~/.pip && \
cd ~/.pip/ && \
echo "[global] \ntrusted-host = pypi.douban.com \nindex-url = http://pypi.douban.com/simple" > pip.conf
If it is because of the network, cuz it takes time to connect the source maybe:
Try to add the following limitation after pip install:
--default-timeout=1000 --no-cache-dir
This may also be caused when your host's network interface uses a smaller than default MTU (which is usually 1500), and the docker container does not know about this and uses a larger MTU.
We faced this on a Gitlab runner that was connected to a VLAN (MTU of 1400). Connections to some hosts worked just fine but some gave persistent issues (amongst which: PyPI, resulting in the error mentioned here).
The solution was to change the MTU for docker and all problems went away.
/etc/docker/daemon.json
{
"mtu": 1400
}

Resources