9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerのベースサイズを変更する方法

Posted at
  • 環境
    • CentOS Linux release 7.8.2003 (Core)
    • Docker Engine 19.03.8(API version: 1.40)
    • docker-compose version 1.25.5

コンテナを作ったらサイズが不足して失敗した

$ docker-compose up -d --no-recreate --build
...省略...
Step 36/48 : RUN unzip payara-5.194.zip
 ---> Running in 6048c43da3e7
Archive:  payara-5.194.zip
   creating: payara5/
...省略...
  inflating: payara5/glassfish/lib/install/applications/__admingui/WEB-INF/extra/dojo-ajax-nodemo-0.4.4.jar
payara5/glassfish/lib/install/applications/__admingui/WEB-INF/extra/dojo-ajax-nodemo-0.4.4.jar:  write error (disk full?).  Continue? (y/n/^C)
warning:  payara5/glassfish/lib/install/applications/__admingui/WEB-INF/extra/dojo-ajax-nodemo-0.4.4.jar is probably truncated
ERROR: Service 'ponsuke-java11' failed to build: The command '/bin/sh -c unzip payara-5.194.zip' returned a non-zero code: 50

コンテナに割り振られるベースサイズの確認方法がわからない

Docker コンテナが利用可能なストレージサイズのことをベースサイズ(basesize)と呼びます。デフォルトではコンテナあたり、10GB です。これでは不足な場合、サイズを拡張することが出来ます。
...省略...
ベースサイズは docker info で確認することが出来ます。
Docker のベースサイズを拡張する - らくがきちょう

ない・・・・
$ docker info
Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 48
 Server Version: 19.03.8
 Storage Driver: overlay2
  Backing Filesystem: <unknown>
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1127.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 62.74GiB
 Name: ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com
 ID: 3OGB:YZDY:MH6T:WLU2:WTYS:3KNG:N6FH:CQCK:UGDK:JATT:7M4U:4WKR
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

ベースサイズを増やす

作成に失敗したコンテナと不要なイメージを削除する

DockerでのDisk使用量を調べる - すずけんメモ

# 作成に失敗したコンテナを削除する
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
07df02ea2663        bdd55645a038        "/bin/sh -c 'unzip p…"   2 hours ago         Up 2 hours                              focused_pascal
$ docker rm -v 07df02ea2663
07df02ea2663

# 使わないイメージやボリュームを削除する
$ docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
...省略...
Total reclaimed space: 4.578GB

docker-storageにベースサイズを設定する

「dm.basesize」を設定すればよいようです。
参考のページでは、dockerデーモンを起動する引数として指定していますが、systemctrlなどで起動する場合は、設定ファイルに記載します。
Dockerの起動設定には、/etc/sysconfig/docker、/etc/sysconfig/docker-network、/etc/sysconfig/docker-storageがあります。
Dockerでルートディスクサイズを調整する - Qiita

/etc/sysconfig/にdockerのファイルなんてなかった・・・のでとりあえず作った。
/etc/sysconfig/docker-storageに以下を書けばいいらしい。

/etc/sysconfig/docker-storage
DOCKER_STORAGE_OPTIONS=--storage-opt dm.basesize={設定したいベースサイズ}
# 1. Dockerを停止する
$ sudo systemctl stop docker
[sudo] password for ponsuke:

# 2. docker-storageを作って設定を書く
$ sudo vi /etc/sysconfig/docker-storage
$ sudo cat /etc/sysconfig/docker-storage
DOCKER_STORAGE_OPTIONS=--storage-opt dm.basesize=30G

# 3. 論理デバイスの管理情報があるディレクトリを削除する
$ sudo rm -rf /var/lib/docker

# 4. Dockerを起動する
$ sudo systemctl start docker

# 5. 一応ちゃんと起動したか見ておく
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-05-06 11:48:46 UTC; 4s ago
     Docs: https://docs.docker.com
 Main PID: 16093 (dockerd)
    Tasks: 25
   Memory: 49.0M
   CGroup: /system.slice/docker.service
           └─16093 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

May 06 11:48:45 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:45.970313402Z" level=info msg="scheme \"unix\" not registered, fallback to default...dule=grpc
May 06 11:48:45 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:45.970331543Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix://...dule=grpc
May 06 11:48:45 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:45.970343468Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
May 06 11:48:45 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:45.991432463Z" level=info msg="Loading containers: start."
May 06 11:48:46 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:46.056116835Z" level=info msg="Default bridge (docker0) is assigned with an IP add... address"
May 06 11:48:46 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:46.090976853Z" level=info msg="Loading containers: done."
May 06 11:48:46 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:46.114952955Z" level=info msg="Docker daemon" commit=afacb8b graphdriver(s)=overla...n=19.03.8
May 06 11:48:46 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:46.115057573Z" level=info msg="Daemon has completed initialization"
May 06 11:48:46 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com dockerd[16093]: time="2020-05-06T11:48:46.140316738Z" level=info msg="API listen on /var/run/docker.sock"
May 06 11:48:46 ip-10-0-6-88.ap-northeast-1.compute.internaldev01.othelve.com systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

コンテナを作り直す

$ docker-compose up -d --no-recreate --build

うまくいかない場合のほかの方法

やってないけど将来のためにメモしておく

daemon.jsonで定義する

【学習メモ】 dockerのbase device sizeをdaemon.jsonで定義 - Qiita

9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?