Resizing Docker containers

为君一笑 提交于 2019-12-23 14:55:13

问题


I am trying to see if size of each docker container can be limited through some configuration.

Following this , I am able to increasing the size of a running container from 10G. Can I shrink it? Trying to shrink threw an error saying online shrinking not supported.

Ideally, I am looking for options to configure and set default container size which containers will inherit when getting created. Docker doc on devicemapper suggested --storage-opt while starting docker daemon. But it does not seem to work.

I would also like to know if size can be limited per container (say during docker run command).

Any pointer towards the correct direction is greatly appreciated. Thanks in advance


回答1:


If you're using the devicemapper graph engine, then storage-opt dm.basesize is the way to go for what you are trying to do. You need to clean out your /var/lib/docker after changing the configuration (note this will wipe all images you currently have, even if you use direct block devices to provision the data and metadata pool devices).

Here are the steps I followed:

$ docker run -ti base/arch df -h /
Filesysem                                    Size  Used Avail Use% Mounted on
/dev/mapper/docker-254:7-73733-b8dc...6d28a  9.8G  335M  8.9G   4% /

So I currently have the default 10G base size.

First, change the configuration to add "--storage-opt dm.basesize=5G":

# vim /etc/systemd/system/docker.service
...
ExecStart=/usr/bin/docker -d -H fd:// -s devicemapper \
    --storage-opt dm.datadev=/dev/vg01/docker-dm-data \
    --storage-opt dm.metadatadev=/dev/vg01/docker-dm-meta \
    --storage-opt dm.basesize=5G

Then, stop Docker (make sure all containers are stopped beforehand, reload config, cleanout /var/lib/docker and restart Docker:

# systemctl stop docker
# systemctl daemon-reload
# rm -rf /var/lib/docker
# systemctl start docker

"docker images" should confirm no images are present.

And now rerun the test:

$ docker run -ti base/arch df -h /
Unable to find image 'base/arch:latest' locally
Pulling repository base/arch
a64697d71089: Download complete 
511136ea3c5a: Download complete 
4bbfef585917: Download complete 
Status: Downloaded newer image for base/arch:latest
Filesystem                                 Size  Used Avail Use% Mounted on
/dev/mapper/docker-254:7-66094...f635ac65  4.8G  322M  4.3G   7% /

And there we have a 5Gb base size.




回答2:


it works with devicemapper settins.

--storage-driver devicemapper --storage-opt dm.basesize=5G


来源:https://stackoverflow.com/questions/26546490/resizing-docker-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!