はじめに
どうも、最近海外ドラマで特にNetflix系のドラマにドハマりしているけんつです。
最近、Laradockを使うときにコンテナをビルドしたらDNSが解決できない問題に苦しめられていました。
なんかすごく詰まったのにあっさりと解決してしまったのでまとめます。
環境
- Ubuntu16.04
- Docker version 18.09.0, build 4d60db4
- docker-compose version 1.23.0, build c8524dc1
問題
Laradockで色々とコンテナをビルドしていた時にこんなエラーが頻発して全然ビルドできなかった
Step 3/12 : RUN apk --update add wget curl git build-base libmemcached-dev libmcrypt-dev libxml2-dev zlib-dev autoconf cyrus-sasl-dev libgsasl-dev supervisor
---> Running in 46add29caab7
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/community: temporary error (try again later)
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
autoconf (missing):
required by: world[autoconf]
build-base (missing):
required by: world[build-base]
cyrus-sasl-dev (missing):
required by: world[cyrus-sasl-dev]
git (missing):
required by: world[git]
libgsasl-dev (missing):
required by: world[libgsasl-dev]
libmcrypt-dev (missing):
required by: world[libmcrypt-dev]
libmemcached-dev (missing):
required by: world[libmemcached-dev]
libxml2-dev (missing):
required by: world[libxml2-dev]
supervisor (missing):
required by: world[supervisor]
wget (missing):
required by: world[wget]
zlib-dev (missing):
required by: world[zlib-dev]
ERROR: Service 'php-worker' failed to build: The command '/bin/sh -c apk --update add wget curl git build-base libmemcached-dev libmcrypt-dev libxml2-dev zlib-dev autoconf cyrus-sasl-dev libgsasl-dev supervisor' returned a non-zero code: 11なぜかfetchできないが、普通にターミナルからcurlなりwgetすると取得できたからdockerコンテナ 内部でDNSを解決できていないのかと考えていた。
それとworkspaceのビルドする際にcomposerを走らせる段階でこんなエラーもでる
Changed current directory to /home/laradock/.composer
Loading composer repositories with package information
[Composer\Downloader\TransportException]
The "https://packagist.org/packages.json" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
composer diagをしてみてもこの通り
Checking platform settings: OK Checking git settings: OK Checking http connectivity to packagist: WARNING [Composer\Downloader\TransportException] The "http://packagist.org/packages.json" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution Checking https connectivity to packagist: WARNING [Composer\Downloader\TransportException] The "https://packagist.org/packages.json" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution Checking github.com rate limit: FAIL [Composer\Downloader\TransportException] The "https://api.github.com/rate_limit" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution Checking disk free space: OK Checking pubkeys: FAIL Missing pubkey for tags verification Missing pubkey for dev verification Run composer self-update --update-keys to set them up Checking composer version:
完全にご臨終してしまう
解決策
↑これをやったら想定した動作をした。
実際には全ておこなったわけではなくて
「dockerのホストであるUbuntuでは、デフォルトでdnsmasq が有効になっていて、 /etc/resolv.confが下記のように自分を見る設定になっている。」
この部分を見て /etc/resolv.conf に
nameserver 8.8.8.8 nameserver 8.8.4.4
を追記したて Docker を再起動するだけで、DNSでコケることがなくなった
おわりに
いつからこうなったんだ…