Reputation: 6017
As the title reads, I'm trying to assign more memory to my container. I'm using an image from docker hub called "aallam/tomcat-mysql" in case that's relevant.
When I start it normally without any special flags, there's a memory limit of 2GB (even though I read that memory is unbounded if not set)
Here are my docker stats
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
ba57d6c9e9d2 0.22% 145.6 MiB / 1.952 GiB 7.29% 508 B / 508 B 0 B / 6.91 MB 68
I tried setting memory explicitly like so but with same results
docker run -d --memory=10g --memory-swap=-1 -e MYSQL_PASSWORD=password -p 3307:3306 -p 8081:8080 aallam/tomcat-mysql
I've read that perhaps the VM is what's restricting it. But then why does docker stats show that container size limit is 2GB?
Upvotes: 218
Views: 370814
Reputation: 4217
You can do this with the update
command.
update Update configuration of one or more containers
Keep in mind you will need to update the swap normally as well but it should prompt you if you do.
docker update ttdb --memory=1G --memory-swap=1G
You can update more than memory using this command.
docker container update, docker update
Options:
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period int Limit the CPU real-time period in microseconds
--cpu-rt-runtime int Limit the CPU real-time runtime in microseconds
-c, --cpu-shares int CPU shares (relative weight)
--cpus decimal Number of CPUs
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
-m, --memory bytes Memory limit
--memory-reservation bytes Memory soft limit
--memory-swap bytes Swap limit equal to memory plus swap: -1 to enable unlimited swap
--pids-limit int Tune container pids limit (set -1 for unlimited)
--restart string Restart policy to apply when a container exits
Upvotes: 0
Reputation: 2388
On Windows with WSL backend, you have to (create and) update the .wslconfig
file, located in your users home directory.
Example: %homepath%/.wslconfig
[wsl2]
memory=60GB
(You have to restart WSL and Docker after editing the file)
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#main-wsl-settings
Upvotes: 5
Reputation: 36773
That 2GB
limit you see is the total memory of the VM (virtual machine) on which docker runs.
If you are using Docker Desktop you can easily increase it from the Whale 🐳 icon in the task bar, then go to Preferences -> Advanced:
But if you are using VirtualBox behind, open VirtualBox, Select and configure the docker-machine assigned memory.
See this for Mac:
https://docs.docker.com/desktop/settings/mac/#advanced
MEMORY By default, Docker for Mac is set to use 2 GB runtime memory, allocated from the total available memory on your Mac. You can increase the RAM on the app to get faster performance by setting this number higher (for example to 3) or lower (to 1) if you want Docker for Mac to use less memory.
For Windows:
https://docs.docker.com/desktop/settings/windows/#advanced
Memory - Change the amount of memory the Docker for Windows' Linux VM uses
Upvotes: 325
Reputation: 601
Allocate maximum memory to your docker machine from (docker preference -> advance )
Screenshot of advance settings:
This will set the maximum limit docker consume while running containers. Now run your image in new container with -m=4g flag for 4 gigs ram or more. e.g.
docker run -m=4g {imageID}
Remember to apply the ram limit increase changes. Restart the docker and double check that ram limit did increased. This can be one of the factor you not see the ram limit increase in docker containers.
Upvotes: 34
Reputation: 1488
If you want to change the default container and you are using Virtualbox, you can do it via the commandline / CLI:
docker-machine stop
VBoxManage modifyvm default --cpus 2
VBoxManage modifyvm default --memory 4096
docker-machine start
Upvotes: 24