I have a suite of Beaker tests running against a docker host.
I dont know the intricacies of how docker handles swap files, but it seems that it doesn't like it.
The Puppet code looks like this:
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'],
}
}
And the error message is as follows:
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
So basically, how do I setup a docker container to where I can run swapon
without it erroring out?
To support swap in Docker you first have to enable cgroup management of memory and wap with these arguments: cgroup_enable=memory swapaccount=1.
If you're using grub it should be in /etc/default/grub and the line to add it to should be either GRUB_CMDLINE_LINUX or GRUB_CMDLINE_LINUX_DEFAULT. After making this change run sudo update-grub and reboot. A little more detail is here: http://docker.readthedocs.org/en/v0.7.3/installation/kernel/
Let me know if this doesn't help and we can go further. If this doesn't help you then attempt to run those commands manually by launching the container in a shell. Run this to get an interactive shell and run the commands: docker run -t -i image_name /bin/bash
So I asked in the
#docker
freenode room, and it turns out it's not actually possible to manage swap within a docker container: