如何设置docker容器的RAM和磁盘空间?
以下是我所拥有的docker容器和图像的详细信息如何设置docker容器的RAM和磁盘空间?,docker,virtual-machine,docker-machine,Docker,Virtual Machine,Docker Machine,以下是我所拥有的docker容器和图像的详细信息 Animeshs-MacBook-Pro:docker_tests animesh$ docker-machine ls NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS celery-test * virtualbox Running tcp://192.168.99.10
Animeshs-MacBook-Pro:docker_tests animesh$ docker-machine ls
NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS
celery-test * virtualbox Running tcp://192.168.99.100:2376 v1.9.1
hello-world - virtualbox Stopped Unknown
Animeshs-MacBook-Pro:docker_tests animesh$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33f0eca77b4c celery-image1 "/bin/bash" 2 hours ago Exited (0) 25 minutes ago current_image
a4607f34b309 ubuntu:latest "/bin/bash" 4 hours ago Exited (0) 3 hours ago celery_app
Animeshs-MacBook-Pro:docker_tests animesh$ docker-machine ssh celery-test
Boot2Docker version 1.9.1, build master : cef800b - Fri Nov 20 19:33:59 UTC 2015
Docker version 1.9.1, build a34a1d5
docker@celery-test:~$ df -h
Filesystem Size Used Available Use% Mounted on
tmpfs 896.6M 889.6M 7.0M 99% /
tmpfs 498.1M 0 498.1M 0% /dev/shm
cgroup 498.1M 0 498.1M 0% /sys/fs/cgroup
none 464.8G 44.0G 420.8G 9% /Users
tmpfs 896.6M 889.6M 7.0M 99% /mnt/sda1/var/lib/docker/aufs
docker@celery-test:~$ exit
Animeshs-MacBook-Pro:docker_tests animesh$ docker start current_image
current_image
Animeshs-MacBook-Pro:docker_tests animesh$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33f0eca77b4c celery-image1 "/bin/bash" 2 hours ago Up 3 seconds current_image
a4607f34b309 ubuntu:latest "/bin/bash" 4 hours ago Exited (0) 3 hours ago celery_app
Animeshs-MacBook-Pro:docker_tests animesh$ docker attach current_image
root@33f0eca77b4c:/# df -h
Filesystem Size Used Avail Use% Mounted on
none 897M 890M 7.0M 100% /
tmpfs 499M 0 499M 0% /dev
tmpfs 499M 0 499M 0% /sys/fs/cgroup
tmpfs 897M 890M 7.0M 100% /etc/hosts
shm 64M 0 64M 0% /dev/shm
root@33f0eca77b4c:/# exit
exit
Animeshs-MacBook-Pro:docker_tests animesh$
我似乎已经用完了VM上的空间
我想为celery-image1图像分配8GB磁盘空间和2GB RAM。我该怎么做
如果在创建容器时可以输入任何命令行参数,我也可以这样做。您可以指定RAM限制
磁盘大小无法限制(但有一些限制)。如果运行
$man docker run
并查找“内存”,您可以找到:
-m, --memory=""
Memory limit (format: <number>[<unit>], where unit = b, k, m or g)
Allows you to constrain the memory available to a container. If the host supports swap memory, then the -m memory setting can be larger than physical RAM. If a limit
of 0 is specified (not using -m), the container's memory is not limited. The actual limit may be rounded up to a multiple of the operating system's page size (the
value would be very large, that's millions of trillions).
--memory-reservation=""
Memory soft limit (format: <number>[<unit>], where unit = b, k, m or g)
After setting memory reservation, when the system detects memory contention or low memory, containers are forced to restrict their consumption to their reservation. So
you should always set the value below --memory, otherwise the hard limit will take precedence. By default, memory reservation will be the same as memory limit.
--memory-swap=""
Total memory limit (memory + swap)
-m,--memory=“”
内存限制(格式:[],其中单位=b、k、m或g)
允许您约束容器的可用内存。如果主机支持交换内存,-m内存设置可以大于物理RAM。如果有限制
如果指定了0(不使用-m),则容器的内存不受限制。实际限制可以四舍五入到操作系统页面大小的倍数(
价值将非常大,即数百万万亿)。
--内存保留=“”
内存软限制(格式:[],其中单位=b、k、m或g)
设置内存保留后,当系统检测到内存争用或内存不足时,容器被迫将其消耗限制为其保留。所以
您应该始终将值设置在--memory以下,否则硬限制将优先。默认情况下,内存保留将与内存限制相同。
--内存交换=“”
总内存限制(内存+交换)
这些是运行$docker run
时可以设置的标志。必须注意的是,您还可以为CPU使用设置一些限制