Ubuntu 18.04上のDockerでコンテナのベースサイズを自在に変える


関連記事

Docker info

# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.09.7
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true

無設定時

#  docker run --storage-opt size=5g -t -i ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
^[[2~latest: Pulling from library/ubuntu
5b7339215d1d: Pull complete 
14ca88e9f672: Pull complete 
a31c3b1caad4: Pull complete 
b054a26005b7: Pull complete 
Digest: sha256:9b1702dcfe32c873a770a32cfd306dd7fc1c4fd134adfb783db68defc8894b3c
Status: Downloaded newer image for ubuntu:latest
docker: Error response from daemon: --storage-opt is supported only for overlay over xfs with 'pquota' mount option.
See 'docker run --help'.

grubの編集

vi /etc/default/grub

GRUB_CMDLINE_LINUX に "rootflags=uquota,pquota" を追加。

sudo grub-mkconfig -o /boot/grub/grub.cfg
docker run --storage-opt size=5g -t -i ubuntu /bin/bash
root@67f434ee5ab8:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay         5.0G  8.0K  5.0G   1% /
tmpfs            64M     0   64M   0% /dev
tmpfs           2.8G     0  2.8G   0% /sys/fs/cgroup
/dev/sda5        55G  8.2G   47G  16% /etc/hosts
shm              64M     0   64M   0% /dev/shm
tmpfs           2.8G     0  2.8G   0% /proc/asound
tmpfs           2.8G     0  2.8G   0% /proc/acpi
tmpfs           2.8G     0  2.8G   0% /proc/scsi
tmpfs           2.8G     0  2.8G   0% /sys/firmware
root@67f434ee5ab8:/# 

サイズが変わった。