Upgrade to Pro — share decks privately, control downloads, hide ads and more …

コンテナは友だち! in RailsDM /container-ga-tokui-na-fri...

KONDO Uchio
November 16, 2017

コンテナは友だち! in RailsDM /container-ga-tokui-na-friends-in-railsdm

Rails Developers Meetup #7
https://techplay.jp/event/631428

KONDO Uchio

November 16, 2017
Tweet

More Decks by KONDO Uchio

Other Decks in Technology

Transcript

  1. த਎ΛݟͯΈΑ͏ wԋश  ௕͘ଘࡏ͢ΔΑ͏ͳϓϩηεΛ࡞ͬͯΈΑ͏ɻ w  ͦͷϓϩηεͷ1*%Λಛఆ͠Α͏ɻ w  ͦͷϓϩηεʹ͍ͭͯɺҎԼͷ৘ใΛऔಘͯ͠ΈΑ͏ɻ

    w  ΧϨϯτσΟϨΫτϦ IJOUQSPD1*%DXE  w  ؀ڥม਺ IJOUQSPD1*%FOWJSPO  w  ϝϞϦϚοϐϯά IJOUQSPD1*%NBQT  w  εϨουͷ਺ IJOUQSPD1*%UBTL
  2.  Ұ࿈ͷॲཧΛͭͳ͛Δ $ cat after-unshare.rb #!/usr/bin/env ruby container_name = ARGV[0]

    raise unless container_name Dir.mkdir "/sys/fs/cgroup/cpu/#{container_name}" rescue puts("skip") File.write "/sys/fs/cgroup/cpu/#{container_name}/tasks", $$.to_s Dir.chroot "/root/#{container_name}" Dir.chdir "/" system "mount -t proc proc /proc" system "hostname #{container_name}.example.jp" exec "bash -l" ࠷ॳʹɺʮVOTIBSFޙʯͷॲཧΛ3VCZͰॻ͘
  3.  Ұ࿈ͷॲཧΛͭͳ͛Δɻ $ sudo unshare \ > --fork \ >

    --pid \ > --mount \ > --uts \ > `pwd`/after-unshare.rb railsdm-7th ઌ΄ͲͷεΫϦϓτʹ࣮ߦݖݶΛ͚ͭͯVOTIBSFͷҾ਺ʹ
  4. ԋशͦͷ w  ઌ΄Ͳͷʮࣗ࡞ίϯςφʯʹ͍ͭͯɺ
 ผͷλʔϛφϧ͔ΒϗετʹೖΓɺҎԼΛ͔֬ΊͯΈΑ͏ɻ w  ϗετ͔Βݟͯίϯςφ͕ʮϓϩηεʯͰ͋Δ͜ͱ w 

    1*%ɺ.PVOUɺ654/BNFTQBDF͕෼཭͍ͯ͠Δ͜ͱ w  ίϯςφ಺Ͱ$16Λ͍͘Β࢖ͬͯ΋ɺϗετͷ$16Λ͔͠ ࢖Θͳ͘ͳΔΑ͏ɺDHSPVQΛઃఆͯ͠ΈΑ͏ɻ·ͨɺ֬ೝ͠Α͏
 IJOUIUUQTBDDFTTSFEIBUDPNEPDVNFOUBUJPOKB+13FE@)BU@&OUFSQSJTF@-JOVY IUNM[email protected]@(VJEFTFDDQVIUNM
  5. 13