Dockerでyum install時に容量越えエラーが出た対応メモ。

Insufficient space in download directory というエラーが出てyum install出来ないのを対応したメモ。


環境

  • OS: Mac OS X 10.11.6
  • Docker: 1.12.1
  • docker-compose: 1.8.0

突然yum installでエラーが発生するようになる

追加のパッケージが必要になり yum install を実行したところエラーが発生した。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# yum install gcc

Error downloading packages:
libgomp-4.8.5-4.el7.x86_64: Insufficient space in download directory /var/cache/yum/x86_64/7/base/packages
* free 0
* needed 130 k
cpp-4.8.5-4.el7.x86_64: Insufficient space in download directory /var/cache/yum/x86_64/7/base/packages
* free 0
* needed 5.9 M
gcc-4.8.5-4.el7.x86_64: Insufficient space in download directory /var/cache/yum/x86_64/7/base/packages
* free 0
* needed 16 M
libmpc-1.0.1-3.el7.x86_64: Insufficient space in download directory /var/cache/yum/x86_64/7/base/packages
* free 0
* needed 51 k
mpfr-3.1.1-4.el7.x86_64: Insufficient space in download directory /var/cache/yum/x86_64/7/base/packages
* free 0

Insufficient space in download directory

ダウンロードディレクトリに十分なスペースが無いというようなエラーのようだ。
df で使用している容量を確認してみる。

1
2
3
4
5
6
7
8
# df -h
Filesystem Size Used Avail Use% Mounted on
none 60G 57G 0 100% /
tmpfs 1000M 0 1000M 0% /dev
tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
/dev/vda2 60G 57G 0 100% /etc/hosts
shm 64M 0 64M 0% /dev/shm
osxfs 931G 308G 623G 34% /var/www/html

volumeしているMacは十分な容量があるのに / 以下は 100% になっている。
調べてみると、ホストからDockerが確保した領域をコンテナとイメージで食いつぶしている模様。
Dockerが確保した容量は、全てのコンテナで利用するようだ。

コンテナとイメージを削除して空き容量を確保する

利用していないコンテナとnoneイメージを削除する。

1
2
$ docker rm `docker ps -aq`
$ docker images | awk '/<none/{print $3}' | xargs docker rmi

容量を確認。

1
2
3
4
5
6
7
8
# df -h
Filesystem Size Used Avail Use% Mounted on
none 60G 55G 1.2G 99% /
tmpfs 1000M 0 1000M 0% /dev
tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
/dev/vda2 60G 55G 1.2G 99% /etc/hosts
shm 64M 0 64M 0% /dev/shm
osxfs 931G 308G 623G 34% /var/www/html

1.2GBしか空かないので一旦全てのイメージを削除する。

1
$ docker images | awk '{print $3}' | xargs docker rmi

再度容量を確認。

1
2
3
4
5
6
7
8
# df -h
Filesystem Size Used Avail Use% Mounted on
none 60G 48G 9.0G 85% /
tmpfs 1000M 0 1000M 0% /dev
tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
/dev/vda2 60G 48G 9.0G 85% /etc/hosts
shm 64M 0 64M 0% /dev/shm
osxfs 931G 308G 623G 34% /var/www/html

十分空き容量が確保できたので yum install を再度実行すると問題なく実行できた。

未解決事項

以下の項目が未調査。

  • Dockerが確保している60GBの値を設定する方法。
  • 全イメージを削除しても48GB利用している理由。

以上です。

Dockerコンテナでapt update が失敗するのを対応したメモ

ローカルで問題なくビルドできたDockerfileが、サーバに移した途端ビルド出来なくなったのを対応したメモ。


環境

  • OS: CentOS Linux release 7.2.1511 (Core)
  • Docker: 1.12.1
  • docker-compose: 1.8.0

Dockerfile

利用したのは簡単なDockerfile。
特に動作に問題はない。

Dockerfile
1
2
3
4
5
6
7
8
9
FROM node:5.12.0

RUN apt update
RUN apt install -y ruby

RUN npm install -g api-mock

EXPOSE 3000
CMD ["api-mock", "/app/mock.md"]

ローカルでは問題無いがサーバでaptがエラー

ローカルで一通り開発が出来たのでサーバに移してビルドしてみたとろ、apt updateでエラーが発生。

Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ docker-compose build
Step 2 : RUN apt-get update
---> Running in 6447ed4d7e03
Err http://security.debian.org jessie/updates InRelease

Err http://security.debian.org jessie/updates Release.gpg
Could not resolve 'security.debian.org'
Err http://httpredir.debian.org jessie InRelease

Err http://httpredir.debian.org jessie-updates InRelease

Err http://httpredir.debian.org jessie Release.gpg
Could not resolve 'httpredir.debian.org'
Err http://httpredir.debian.org jessie-updates Release.gpg
Could not resolve 'httpredir.debian.org'
Reading package lists...
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/InRelease

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/InRelease

W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease

W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg Could not resolve 'security.debian.org'

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/Release.gpg Could not resolve 'httpredir.debian.org'

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/Release.gpg Could not resolve 'httpredir.debian.org'

W: Some index files failed to download. They have been ignored, or old ones used instead.

調べてみると、外部のDNSを参照出来ていないらしい。
/etc/resolv.conf というのに下記DNSサーバを指定すればいいとのこと。

Dockerfile
1
2
RUN echo  nameserver 8.8.8.8 >> /etc/resolv.conf
RUN echo nameserver 8.8.4.4 >> /etc/resolv.conf

しかし、再度試すも失敗。

docker-composeではなく直接起動してみる

--dns というオプションで起動できるみたいなので直接実行してみる。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ docker run -it --rm --dns=8.8.8.8 --dns=8.8.4.4 node:5.12.0 apt update
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:2 http://security.debian.org jessie/updates/main amd64 Packages [389 kB]
Ign http://httpredir.debian.org jessie InRelease
Get:3 http://httpredir.debian.org jessie-updates InRelease [142 kB]
Get:4 http://httpredir.debian.org jessie Release.gpg [2373 B]
Get:5 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Get:6 http://httpredir.debian.org jessie Release [148 kB]
Get:7 http://httpredir.debian.org jessie/main amd64 Packages [9032 kB]
Fetched 9795 kB in 19s (512 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
5 packages can be upgraded. Run 'apt list --upgradable' to see them.

問題無く動くが--dnsを外すと動かない。

DNSの設定はホストのresolv.confを参照していた

--dnsってどういうい仕様なんだろうとリファレンスを読んでいると、次の一文を見つけた。

Docker は各コンテナの /etc/resolv.conf をホストマシン上( docker デーモンが動作中 )の /etc/resolv.conf のように作成します。

コンテナのDNSを設定

ホストマシンのresolv.confがそのまま反映されるらしい。
さっそくホストマシンの/etc/resolv.confを確認してみる。

/etc/resolv.conf
1
nameserver 0.0.0.0

これのみの記載のため、先程のDNSをふたつ追加する。

/etc/resolv.conf
1
2
3
nameserver 0.0.0.0
nameserver 8.8.8.8
nameserver 8.8.4.4

この状態で再度ビルドすると正常にapt updateが実行できビルドが通った。

以上です。

gitでpre-commitを作成したのに動かない対応メモ。

git で .git/hooks/pre-commit に処理を書いておくとコミット前に実行され、0以外が返るとコミットしないという仕組みがありますが、pre-commitを置いたのに動かなかったのを対応したメモです。


環境

  • OS: Mac OS X 10.11.6
  • Git: 2.1.0

実行権限をつける

単純に実行権限が必要だったので、以下で解決する。

1
$ chmod a+x .git/hooks/pre-commit

以上です。

© 2024 磁力式駆動 All Rights Reserved.
Theme by hiero