Ubuntu를 사용하여 Docker 컨테이너 내에 pip 패키지를 설치할 수 없습니다.
나는 파이썬 응용 프로그램에서 도커를 사용 하는 무화과 가이드 를 따르고 있지만 도 커가 명령에 도달하면
RUN pip install -r requirements.txt
다음과 같은 오류 메시지가 나타납니다.
Step 3 : RUN pip install -r requirements.txt
---> Running in fe0b84217ad1
Collecting blinker==1.3 (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', gaierror(-2, 'Name or service not known'))': /simple/blinker/
이것은 여러 번 반복되고 다른 메시지가 나타납니다.
Could not find any downloads that satisfy the requirement blinker==1.3 (from -r requirements.txt (line 1))
No distributions at all found for blinker==1.3 (from -r requirements.txt (line 1))
따라서 어떤 이유로 pip는 도커 컨테이너 내부의 패키지에 액세스 할 수 없습니다. 인터넷 액세스를 허용하기 위해해야 할 일이 있습니까?
그러나 pip는 도커 컨테이너 외부에 설치하는 데 잘 작동하며 정확한 패키지 ( blinker==1.3) 로도 잘 작동 하므로 문제가되지 않습니다. 또한이 문제는 해당 패키지에만 국한되지 않습니다. pip install모든 패키지에 대한 명령 과 동일한 문제가 발생 합니다.
여기에서 무슨 일이 일어나고 있는지 아는 사람이 있습니까?
문제는 Docker가 적절한 DNS 서버를 사용하지 않는다는 사실에서 비롯됩니다. 세 가지 방법으로 수정할 수 있습니다.
1. 로컬 구성에 Google DNS 추가
/etc/resolv.conf 수정 및 끝에 다음 줄 추가
# Google IPv4 nameservers nameserver 8.8.8.8 nameserver 8.8.4.4
다른 DNS 서버를 추가하려면 여기를 참조하십시오 .
그러나이 변경은 영구적이지 않습니다 ( 이 스레드 참조 ). 영구적으로 만들려면 : $ sudo nano /etc/dhcp/dhclient.conf 주석 처리를 제거하고 domain-name-server 앞에 추가 된 줄을 편집합니다.prepend domain-name-servers 8.8.8.8, 8.8.4.4;
dhclient 다시 시작 : $ sudo dhclient.
2. Docker 구성 수정
문서에 설명 된 대로 :
데스크탑에서 Ubuntu 또는 Ubuntu 파생물을 실행하는 시스템은 일반적으로 /etc/resolv.conf 파일에서 기본 이름 서버로 127.0.0.1을 사용합니다.
Docker에서 사용할 DNS 서버를 지정하려면 다음을 수행하십시오.
1. Log into Ubuntu as a user with sudo privileges.
2. Open the /etc/default/docker file for editing :
$ sudo nano /etc/default/docker
3. Add the following setting for Docker.
DOCKER_OPTS="--dns 8.8.8.8"
4. Save and close the file.
5. Restart the Docker daemon :
$ sudo systemctl restart docker
3. Docker를 실행할 때 매개 변수 사용
docker를 실행할 때 다음 매개 변수를 추가하기 만하면됩니다. --dns 8.8.8.8
나는 똑같은 문제가 있었고 한동안 나를 괴롭 혔고 온라인에서 많은 해결책을 시도했지만 소용이 없었습니다. 그러나 마침내 다음과 같이 해결했습니다.
달리는:
Ubuntu 16.04
docker Server 18.03.0-ce
DNS 서버의 주소를 찾으십시오.
다음 명령을 실행하여 DNS 서버의 주소를 찾으십시오.
$: nmcli dev show | grep 'IP4.DNS' IP4.DNS[1]: 192.168.210.2Docker 데몬 업데이트
에 고정 표시기 설정 파일 만들기
/etc/docker/daemon.json.( 아직없는 경우를 파일에 다음과 같은 내용을) 추가합니다 :{ "dns": ["192.168.210.2", "8.8.8.8"] }배열의 첫 번째 항목은 네트워크의 DNS 서버이고 두 번째 항목은 네트워크의 DNS를 사용할 수없는 경우 대비책으로 Google의 DNS 서버입니다.
파일을 저장 한 다음 Docker 서비스를 다시 시작하십시오.
$: sudo service docker restart
좋아, 내 도커 머신을 다시 시작하면 문제가 해결됩니다. 감사합니다 – ismailsunni
이것이 저에게 해결책이었습니다.
docker-machine restart <machine-name>
나를 위해 단순히 docker 데몬을 다시 시작하는 것이 도움이되었습니다.
service docker restart
도커 빌드 명령에 --network = host를 추가해야했습니다.
docker build --network=host -t image_name .
Ubuntu 사용자의 경우
Docker 구성에 새 DNS 주소를 추가해야합니다.
sudo nano /lib/systemd/system/docker.service
ExecStar 뒤에 DNS를 추가합니다.
--dns 10.252.252.252 --dns 10.253.253.253
다음과 같이 보일 것입니다.
ExecStart=/usr/bin/dockerd -H fd:// --dns 10.252.252.252 --dns 10.253.253.253
다음을 수행하십시오.
systemctl daemon-reload
sudo service docker restart
작동해야합니다.
내 경우에는,로 docker version 1.13.0와 docker-machine 0.9.0에서 Ubuntu 16.04나는 다음과 같이 약간 Tanzaho의 대답 (2 수정 도커의 설정)를 수정했습니다 :
sudo 권한이있는 사용자로 Ubuntu에 로그인합니다.
편집을 위해 / etc / default / docker 파일을 엽니 다.
sudo vim /etc/default/dockerDocker에 대해 다음 설정을 추가하십시오.
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"파일을 저장하고 닫습니다.
Docker 데몬을 다시 시작합니다.
sudo service docker restart
For me, I was unable to install pip due to the docker's DNS not configured properly. I've tried the above steps, however, configuring docker DNS to Google DNS does not work for my laptop. Docker's DNS can be properly configured only if I set its DNS to my laptop's assigned IP.
If you use Ubuntu, you can use the following steps to configure your docker's DNS:
Find out your device's assigned IP. You can find this by either
- Checking the inet addr of your ethernet or wlan in
ifconfig - Choosing any address in
nmcli dev show | grep 'DNS'
- Checking the inet addr of your ethernet or wlan in
Edit dns in
/etc/docker/daemon.json(create this file if it doesn't exist previously){ "dns": ["your_ip_in_step_1"] }Restart docker:
sudo service docker restart
As a Docker newbie, I had a problem that manifested itself in this way when I was following the tutorial for Docker at:
https://docs.docker.com/get-started/part2
I'm using Docker 17.03.1-ce on a corporate LAN.
I checked and double checked my DNS settings. I'd used various ways of configuring the DNS that I'd found in my searches across the Internet. Some caused errors on startup. The approach that I ultimately settled upon for configuring the DNS was the one in the Troubleshoot Linux section of the above link above where the DNS is configured via the daemon.json file in the /etc/docker directory.
However, I still had this same issue. What finally solved the problem for me was the configuration of the proxy via the http_proxy and https_proxy environment variables. I had them specified in my Dockerfile, but I neglected to do so before the RUN pip command.
Even though it appeared to be a DNS issue, moving these ENV commands ahead of the RUN command made the difference for me. In case that is helpful for anyone with this problem.
I do not know the reason, but the error means that pip is trying to resolve the /simple/blinker/ as a DNS hostname instead of the pypi.python.org part, which seems very odd since I cannot even come up with any URL for which urlparse could return such a string as a hostname part. I'd check if there is some problem with ~/.pip/pip.conf
I had same problem.The cause of error is proxy.
So, I edit Dockerfile following
RUN pip install -r /app/requirements.txt --proxy=http://user:pass@addr:port
In case someone is reading this using docker-compose. I managed to resolve this by changing my yaml file as follows
version: 3.4
service: my-app
build:
context: .
network: host
which is equivalent to writing
docker build . --network host
Let it run. Sometimes pypi is having connection issues which are noisily put in your face to make you think it is broke. Just to be sure, let it roll, you might find it works it out for itself.
The bottom line, despite these red error lines, is "Successfully built"
$ docker build .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM docker-registry.aws.example.com:5000/cmcrc/python2:20160517120608
---> 1e5034711aa9
Step 2 : RUN pip install prometheus-client requests
---> Running in f3c580fc93ae
Collecting prometheus-client
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe15a1d8610>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/prometheus-client/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe15a1d87d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/prometheus-client/
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe15a1d8990>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/prometheus-client/
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe15a1d8b50>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/prometheus-client/
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe15a1d8d10>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/prometheus-client/
Downloading prometheus_client-0.0.13.tar.gz
Collecting requests
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe159e9d4d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/requests/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe159e9da10>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/requests/
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe159e9dc50>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/requests/
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe159e9de10>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/requests/
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fe159e9dfd0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/requests/
Downloading requests-2.10.0-py2.py3-none-any.whl (506kB)
Building wheels for collected packages: prometheus-client
Running setup.py bdist_wheel for prometheus-client: started
Running setup.py bdist_wheel for prometheus-client: finished with status 'done'
Stored in directory: /root/.cache/pip/wheels/04/94/f5/b803b2ff65e8344e99ca99b7f7cb8194224017167809a32b78
Successfully built prometheus-client
Installing collected packages: prometheus-client, requests
Successfully installed prometheus-client-0.0.13 requests-2.10.0
---> 19c5e3cfe08f
Removing intermediate container f3c580fc93ae
Successfully built 19c5e3cfe08f
Configuring docker DNS to Google DNS (8.8.8.8) or 10.0.0.2 did not work in my company environment.
Running: $ drill @8.8.8.8 www.amazon.com or @10.0.0.2 confirmed this.
In order to find a DNS that would work I ran: $ drill www.amazon.com and it gave me the DNS IP that is being used in my network.
Then I set it in Ubuntu using the following step to configure docker's DNS.
Changed dns in /etc/docker/daemon.json
{
"dns": ["the DNS ip from step1"]
}
Restart docker: sudo service docker restart
Im new to Docker and tried all the methods mentioned here, but still didn't get it right. the Docker version was 18, and ubuntu version was 16. I tried this method:- First i was building docker with company's internet network. this network is blocking some sites or some how things didnt go well here. So secondly i connected to my very own network(which im using in mobile phone, for example) and tried. things went right. requirement.txt was installed successfully, and docker was build.
For me, it was caused by being connected to my university VPN. Disconnecting "solved" the problem.
'Program Club' 카테고리의 다른 글
| NSURLSession : URL 요청에 대한 시간 초과를 늘리는 방법은 무엇입니까? (0) | 2020.12.03 |
|---|---|
| AngularJS 지시문에서 자식 요소 찾기 (0) | 2020.12.03 |
| 문자열 인덱스가있는 Python 배열 (0) | 2020.12.03 |
| 상단에 행을 삽입 할 때 uitableview를 정적으로 유지 (0) | 2020.12.03 |
| Html.Hidden과 Html.HiddenFor의 차이점은 무엇입니까? (0) | 2020.12.03 |