I'm following the fig guide to using docker with a python application, but when docker gets up to the command
RUN pip install -r requirements.txt
I get the following error message:
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/
This repeats several times and then I get another message:
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))
So for some reason pip can't access any packages from inside a docker container. Is there anything I need to do to allow it internet access?
However pip works fine to install things outside of the docker container, and worked fine even with that exact package (blinker==1.3
) so that's not the problem. Also this problem isn't specific to that package. I get the same issue with any pip install
command for any package.
ここで何が起こっているのか誰か分かりますか?
ベストアンサー1
問題は、Docker が適切な DNS サーバーを使用していないことに起因します。次の 3 つの方法で修正できます。
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