我有一套针对 docker 主机运行的烧杯测试。
我不知道 docker 如何处理交换文件的复杂性,但它似乎不喜欢它。
Puppet 代码如下所示:
exec { 'Create swap file':
command => "/bin/dd if=/dev/zero of=${swapfile} bs=1M count=${swapfilesize_mb}",
creates => $swapfile,
}
exec { 'Attach swap file':
command => "/sbin/mkswap ${swapfile} && /sbin/swapon ${swapfile}",
require => Exec['Create swap file'],
unless => "/sbin/swapon -s | grep ${swapfile}",
}
if $add_mount {
mount { 'swap':
ensure => present,
fstype => swap,
device => $swapfile,
dump => 0,
pass => 0,
require => Exec['Attach swap file'],
}
}
错误信息如下:
Info: Loading facts
Notice: Compiled catalog for centos-6-x64 in environment production in 0.22 seconds
Info: Applying configuration version '1411345072'
Notice: /Stage[main]/Swap_file/Exec[Create swap file]/returns: executed successfully
Notice: /Stage[main]/Swap_file/Exec[Attach swap file]/returns: mkswap: /tmp/swapfile: warning: don't erase bootbits sectors
Notice: /Stage[main]/Swap_file/Exec[Attach swap file]/returns: on whole disk. Use -f to force.
Notice: /Stage[main]/Swap_file/Exec[Attach swap file]/returns: Setting up swapspace version 1, size = 5116 KiB
Notice: /Stage[main]/Swap_file/Exec[Attach swap file]/returns: no label, UUID=ceb75f7d-ae8b-4781-bd1b-4123bec9bcf1
Notice: /Stage[main]/Swap_file/Exec[Attach swap file]/returns: swapon: /tmp/swapfile: swapon failed: Input/output error
Error: /sbin/mkswap /tmp/swapfile && /sbin/swapon /tmp/swapfile returned 255 instead of one of [0]
Error: /Stage[main]/Swap_file/Exec[Attach swap file]/returns: change from notrun to 0 failed: /sbin/mkswap /tmp/swapfile && /sbin/swapon /tmp/swapfile returned 255 instead of one of [0]
Notice: /Stage[main]/Swap_file/Mount[swap]: Dependency Exec[Attach swap file] has failures: true
Warning: /Stage[main]/Swap_file/Mount[swap]: Skipping because of failed dependencies
Notice: Finished catalog run in 0.26 seconds
所以基本上,我如何设置一个 docker 容器到我可以运行swapon
而不会出错的地方?
要在 Docker 中支持交换,您首先必须启用内存的 cgroup 管理并使用以下参数进行 wap:cgroup_enable=memory swapaccount=1。
如果您使用 grub,它应该在 /etc/default/grub 中,并且添加它的行应该是 GRUB_CMDLINE_LINUX 或 GRUB_CMDLINE_LINUX_DEFAULT。进行此更改后,运行 sudo update-grub 并重新启动。更多细节在这里: http ://docker.readthedocs.org/en/v0.7.3/installation/kernel/
如果这没有帮助,请告诉我,我们可以走得更远。如果这对您没有帮助,请尝试通过在 shell 中启动容器来手动运行这些命令。运行此命令以获取交互式 shell 并运行以下命令: docker run -t -i image_name /bin/bash
所以我在
#docker
freenode 房间里询问,结果发现在 docker 容器中管理交换实际上是不可能的: