Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Docker-Compose with storage options (size)

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
like image 884
ichi Avatar asked Jan 07 '17 13:01

ichi


People also ask

How much memory should I allocate to Docker?

The minimum allowed value is 4m . Because kernel memory cannot be swapped out, a container which is starved of kernel memory may block host machine resources, which can have side effects on the host machine and on other containers.

Can I limit the file size CPU utilization for a docker in my machine?

Limit Docker Container CPU Usage You can also use the --cpu-shares option to give the container a greater or lesser proportion of CPU cycles. By default, this is set to 1024. To find more options for limiting container CPU usage, please refer to Docker's official documentation.

Does Docker compose scale?

While docker-compose scale is useful for small environments like a single Docker host running in production. It is also very useful for developers running Docker on their workstation. It can help them test how the app will scale in production, and under different circumstances.


1 Answers

Try this:

storage_opt:
  size: '1G'

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

like image 51
Nguyen Hoang Hiep Avatar answered Sep 21 '22 06:09

Nguyen Hoang Hiep