How to assign more memory to docker container

2020-01-25 05:22发布

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?

3条回答
该账号已被封号
2楼-- · 2020-01-25 05:54

That 2GB limit you see is the total memory of the VM in which docker runs.

If you are using docker-for-windows or docker-for-mac you can easily increase it from the Whale

查看更多
smile是对你的礼貌
3楼-- · 2020-01-25 05:59

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.

查看更多
Anthone
4楼-- · 2020-01-25 06:00

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
查看更多
登录 后发表回答