Dokku applications are deployed as Docker containers to your virtual machine's operating system. There are three primary container types for each of your applications:
1. Build containers are created temporarily during each deployment and are responsible for tasks such as installing components and compiling assets.
2. Deploy containers are created after the build container successfully finishes its work and represent the active instance of your application.
3. Run containers are one-off containers that are spawned by scheduled jobs (e.g. cron) or created on-demand by you (see Dokku documentation).
Each container type consumes CPU and memory that is proportional to the amount of work that it is doing. For example, build containers can take up a significant amount of CPU when installing/compiling application dependencies based on the amount of filesystem I/O being performed.
Dokku provides the ability to set resource limits for each container type. This feature can be useful if you observe an application using significant resources during a new deployment and impacting your existing deployed application, or if you are operating multiple applications side-by-side.
Example: set a CPU limit of 25% during the build step:
dokku docker-options:add my-app-name build "--cpus='0.25'"
Example: set a memory limit of 256 MB for a deployed application:
dokku docker-options:add my-app-name deploy "-m='256m'"
You can also combine container types. Heres how to set a memory limit of 256 MB for deployed and one-off run containers:
dokku docker-options:add my-app-name deploy,run "-m='256m'"
And individual options can be combined. This example shows a CPU and memory limit for every type container:
dokku docker-options:add my-app-name build,deploy,run "--cpus='0.25' -m='256m'"
To view all configured options:
dokku docker-options:report [my-app-name]
Note the above command will display any options that have been set via Dokku plugins.
To remove a command that you set previously, do
dokku docker-options:remove my-app-name <phase(s)> OPTION
For additional reference about Docker container resources, see the official documentation.
Please be aware that setting resource limits will affect the performance of your applications if they require more resources than permitted by the limit. In this case, it is more optimal to upsize your virtual machine to the appropriate sized instance type to gain additional system resources. To determine the best instance type, you can use the built-in htop command or cadvisor monitoring tool to assess the amount of virtual memory and CPU utilized by your application(s).