14

I can apply disk size quota with "--storage-opt size=1536M" argument when working under devicemapper. For example:

docker run -dt --name testing --storage-opt size=1536M ubuntu

the problem is, how can I do this by using docker-compose, via a compose *.yml file.

thanks.

AN ALTERNATIVE SOLUTION:

Use devicemapper as default storage driver for Docker and set basesize for every container.

To use devicemapper as the default:

1) apt-get install lvm2 thin-provisioning-tools

2) change /etc/default/docker as this:

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

3) do these one by one:

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

4) now your containers have only 3GB space. In addition, you can define vol. space when using RUN command with devicemapper (size must be equal or bigger than basesize). For eg:

docker run --storage-opt size=1536M ubuntu
ichi
  • 151
  • 1
  • 1
  • 8

1 Answers1

4

Try this:

storage_opt:
  size: '1G'

as in https://docs.docker.com/compose/compose-file/compose-file-v2/

Robert Hensing
  • 6,708
  • 18
  • 23
  • 2
    Have you tested this ? Whats your docker version? I get 'Unsupported config option' on 18.05.0-ce – webminal.org Jul 03 '18 at 07:32
  • 11
    If anyone else finds this, the 'storage_opt' is currently not available in V3 compose files (3.7 being current as of writing). It was however available in V2 but was removed to V3 (which is apparently a complete re-implementation). So don't waste your time with storage_opts for compose files with V3! – Niclas May 17 '19 at 12:26
  • to be more specific it is in version '2.1'. It concerns because a specific version of rancher uses docker compose 2.0 and 1.0 – Vinujan.S Jun 14 '19 at 12:31
  • I tested with docker-compose v2, not sure what is my docker version then – Nguyen Hoang Hiep Dec 17 '19 at 02:58