web-dev-qa-db-ja.com

Dockerプル:TLSハンドシェイクタイムアウト

私はこれを一貫して取得します(Ubuntu 16.04 LTS):

$ docker pull nginx
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout

ただし、curl TLSは正常に機能します(認証エラーは別として)。

$ curl https://registry-1.docker.io/v2/
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}

(Dockerを模倣する)小さなgolangプログラムでも問題なく動作します。

package main
import (
    "fmt"
    "io/ioutil"
    "net/http"
)
func main() {
    resp, err := http.Get("https://registry-1.docker.io/v2/")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    fmt.Println("Got: ", string(body))
}

Docker TLSタイムアウト要求のpcap:

reading from file docker-timeout.pcap, link-type LINUX_SLL (Linux cooked)
00:38:54.782452 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [S], seq 26945613, win 29200, options [mss 1460,sackOK,TS val 1609360 ecr 0,nop,wscale 7], length 0
00:38:54.878630 IP registry-1.docker.io.https > my-ubuntu.52036: Flags [S.], seq 2700732154, ack 26945614, win 26847, options [mss 1460,sackOK,TS val 947941366 ecr 1609360,nop,wscale 8], length 0
00:38:54.878691 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [.], ack 1, win 229, options [nop,nop,TS val 1609384 ecr 947941366], length 0
00:38:54.878892 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1609384 ecr 947941366], length 155
00:38:55.175931 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1609459 ecr 947941366], length 155
00:38:55.475954 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1609534 ecr 947941366], length 155
00:38:56.076327 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1609684 ecr 947941366], length 155
00:38:57.280103 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1609985 ecr 947941366], length 155
00:38:59.684095 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1610586 ecr 947941366], length 155
00:39:04.492102 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1611788 ecr 947941366], length 155
00:39:04.879468 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [F.], seq 156, ack 1, win 229, options [nop,nop,TS val 1611884 ecr 947941366], length 0
00:39:04.976015 IP registry-1.docker.io.https > my-ubuntu.52036: Flags [.], ack 1, win 105, options [nop,nop,TS val 947943890 ecr 1609384,nop,nop,sack 1 {156:157}], length 0
00:39:04.976073 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1611909 ecr 947943890], length 155
00:39:05.275922 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1611984 ecr 947943890], length 155
00:39:05.876104 IP my-ubuntu.52036 > registry-1.docker.io.https: Flags [P.], seq 1:156, ack 1, win 229, options [nop,nop,TS val 1612134 ecr 947943890], length 155

何が問題になっているのでしょうか?

16
Willem

net/http: TLS handshake timeoutは、インターネット接続が遅いことを意味します。接続タイムアウトのデフォルト値が環境に対して小さすぎます。残念ながら、Dockerには接続タイムアウトを変更できる設定がありません。独自の レジストリキャッシュ をどこか別の場所に作成して、そこからイメージをプルすることもできます。

17
Azamat Hackimov

同じ問題が発生します。次に、Azamat Hackimovの答えは私を正しい方向に向けました。私のマシンは、特に起動時にサービスを起動したいときに、いくらか遅いです。そのため、短いタイムアウトが発生し、リクエストが強制終了されます。

これは私の回避策です:

docker pull $IMAGE || docker pull $IMAGE ||  docker pull $IMAGE || docker pull $IMAGE

リクエストでサーバーをハンマーで叩くだけです。通常、2つ目は成功します。

4
JaM

私の場合、サーバーはNATおよびプロキシの背後にあり、現在の端末で実行したプロキシを自動検出するように設定されています。エクスポートプロキシ設定があります。

root@k8master:~/runner# export http_proxy="http://192.168.10.208:3128"
root@k8master:~/runner# docker pull gitlab/gitlab-runner:latest
latest: Pulling from gitlab/gitlab-runner
7b722c1070cd: Pull complete 
5fbf74db61f1: Pull complete 
ed41cb72e5c9: Pull complete 
7ea47a67709e: Pull complete 
ae336ceeca88: Pull complete 
f9f79780e6cf: Pull complete 
67e622273f37: Pull complete 
bc84c40af701: Pull complete 
69e36092e9de: Pull complete 
Digest: sha256:b1f5387942aaaf8c220f6613a1e96ba2cbcb6c58a5e47ca0df8ae3216720a15e
Status: Downloaded newer image for gitlab/gitlab-runner:latest
4
Mansur Ali

最初にdocker run hello-worldを使用して同等の問題が発生しました。これにより、https://registry-1.docker.io/v2/を使用して画像をダウンロードし、結果として

docker: Error response from daemon: Get https://registry-1.docker.io/v2/: proxyconnect tcp: net/http: TLS handshake timeout.

何時間もウェブを検索して、これが、ubuntu 18.04と現在のdockerリリースを使用している一部のユーザーで、プロキシの背後で発生していることがわかりました。回避策は、http-proxy構成のみを残すためにすべてのhttps-proxy構成を削除して、http(httpsではない)のダウンロードを強制することです。

わからない、本当の理由は何ですか。

(ちなみに、composerおよびpackagistで同等の「TLSハンドシェイク」問題が発生しました。これは、デフォルトでubuntuによって提供されなかったcacert.pemファイルが欠落しているためでした。多分これはdocker-problemは同じ方向に進んでいますか?)

4
The Bndr

プライベートレジストリを使用している場合は、その証明書を/etc/docker/certs.d/registryname/ca.crtに配置する必要があります

registrynameはそれに応じて変更されます

また、[〜#〜] mtu [〜#〜]サイズを1300に変更してください。これもエラーを解決するために行った1つのことでした。レジストリ1は、すでに完了している可能性があります。 MTU変更のコマンド

ip link set dev eth0 mtu 1300

MTUサイズは、インターネット速度が本当に良い場合にこのエラーを回避するために確認することが重要です

3
rebelution

Dockerデーモンプロキシが正しく設定されていない場合、TLS handshake timeoutエラーが発生する可能性があります。

# verify docker daemon proxy configuration
/etc/systemd/system/docker.service.d/proxy.conf

# flush changes
Sudo systemctl daemon-reload

# restart docker service
Sudo systemctl restart docker 

詳細については、 https://docs.docker.com/config/daemon/systemd/#httphttps-proxy を参照してください

0
wisbucky

私にとってうまくいったのは、別のネットワークインターフェイスを使用することでした。イーサネット(有線)で接続する代わりに、wifiに切り替えました。問題が解決しました。

ちなみに、私はRaspbian Stretchのフレッシュインストールをしていました。

0
bandaangosta

上記の回答のどれも私の問題を解決することはできませんが、以下 https://github.com/helm/helm/issues/522 でうまくいくことがわかりました!

その変更の後、私の会社のITアパートは解決策を見つけました。私は、プロキシにhttps:// urlでhttps_proxy環境変数を使用しました。これは、私たちが使用しているほとんどのツールで機能しますが、helmまたは新しいkubeでは機能しません。 TLSハンドシェイクに問題があるようです。 https://からhttp://のURLに切り替えました(例:https_proxy = http:// myproxy)。これですべてが正常に動作します。

0
Fei