docker_cli_daemon_test.go 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  1. // +build daemon,!windows
  2. package main
  3. import (
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "io/ioutil"
  8. "net"
  9. "os"
  10. "os/exec"
  11. "path"
  12. "path/filepath"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "sync"
  17. "time"
  18. "github.com/docker/docker/pkg/integration/checker"
  19. "github.com/docker/libnetwork/iptables"
  20. "github.com/docker/libtrust"
  21. "github.com/go-check/check"
  22. )
  23. func (s *DockerDaemonSuite) TestDaemonRestartWithRunningContainersPorts(c *check.C) {
  24. if err := s.d.StartWithBusybox(); err != nil {
  25. c.Fatalf("Could not start daemon with busybox: %v", err)
  26. }
  27. if out, err := s.d.Cmd("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top"); err != nil {
  28. c.Fatalf("Could not run top1: err=%v\n%s", err, out)
  29. }
  30. // --restart=no by default
  31. if out, err := s.d.Cmd("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top"); err != nil {
  32. c.Fatalf("Could not run top2: err=%v\n%s", err, out)
  33. }
  34. testRun := func(m map[string]bool, prefix string) {
  35. var format string
  36. for cont, shouldRun := range m {
  37. out, err := s.d.Cmd("ps")
  38. if err != nil {
  39. c.Fatalf("Could not run ps: err=%v\n%q", err, out)
  40. }
  41. if shouldRun {
  42. format = "%scontainer %q is not running"
  43. } else {
  44. format = "%scontainer %q is running"
  45. }
  46. if shouldRun != strings.Contains(out, cont) {
  47. c.Fatalf(format, prefix, cont)
  48. }
  49. }
  50. }
  51. testRun(map[string]bool{"top1": true, "top2": true}, "")
  52. if err := s.d.Restart(); err != nil {
  53. c.Fatalf("Could not restart daemon: %v", err)
  54. }
  55. testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ")
  56. }
  57. func (s *DockerDaemonSuite) TestDaemonRestartWithVolumesRefs(c *check.C) {
  58. if err := s.d.StartWithBusybox(); err != nil {
  59. c.Fatal(err)
  60. }
  61. if out, err := s.d.Cmd("run", "-d", "--name", "volrestarttest1", "-v", "/foo", "busybox"); err != nil {
  62. c.Fatal(err, out)
  63. }
  64. if err := s.d.Restart(); err != nil {
  65. c.Fatal(err)
  66. }
  67. if _, err := s.d.Cmd("run", "-d", "--volumes-from", "volrestarttest1", "--name", "volrestarttest2", "busybox", "top"); err != nil {
  68. c.Fatal(err)
  69. }
  70. if out, err := s.d.Cmd("rm", "-fv", "volrestarttest2"); err != nil {
  71. c.Fatal(err, out)
  72. }
  73. out, err := s.d.Cmd("inspect", "-f", "{{json .Mounts}}", "volrestarttest1")
  74. c.Assert(err, check.IsNil)
  75. if _, err := inspectMountPointJSON(out, "/foo"); err != nil {
  76. c.Fatalf("Expected volume to exist: /foo, error: %v\n", err)
  77. }
  78. }
  79. // #11008
  80. func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) {
  81. err := s.d.StartWithBusybox()
  82. c.Assert(err, check.IsNil)
  83. out, err := s.d.Cmd("run", "-d", "--name", "top1", "--restart", "always", "busybox:latest", "top")
  84. c.Assert(err, check.IsNil, check.Commentf("run top1: %v", out))
  85. out, err = s.d.Cmd("run", "-d", "--name", "top2", "--restart", "unless-stopped", "busybox:latest", "top")
  86. c.Assert(err, check.IsNil, check.Commentf("run top2: %v", out))
  87. testRun := func(m map[string]bool, prefix string) {
  88. var format string
  89. for name, shouldRun := range m {
  90. out, err := s.d.Cmd("ps")
  91. c.Assert(err, check.IsNil, check.Commentf("run ps: %v", out))
  92. if shouldRun {
  93. format = "%scontainer %q is not running"
  94. } else {
  95. format = "%scontainer %q is running"
  96. }
  97. c.Assert(strings.Contains(out, name), check.Equals, shouldRun, check.Commentf(format, prefix, name))
  98. }
  99. }
  100. // both running
  101. testRun(map[string]bool{"top1": true, "top2": true}, "")
  102. out, err = s.d.Cmd("stop", "top1")
  103. c.Assert(err, check.IsNil, check.Commentf(out))
  104. out, err = s.d.Cmd("stop", "top2")
  105. c.Assert(err, check.IsNil, check.Commentf(out))
  106. // both stopped
  107. testRun(map[string]bool{"top1": false, "top2": false}, "")
  108. err = s.d.Restart()
  109. c.Assert(err, check.IsNil)
  110. // restart=always running
  111. testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ")
  112. out, err = s.d.Cmd("start", "top2")
  113. c.Assert(err, check.IsNil, check.Commentf("start top2: %v", out))
  114. err = s.d.Restart()
  115. c.Assert(err, check.IsNil)
  116. // both running
  117. testRun(map[string]bool{"top1": true, "top2": true}, "After second daemon restart: ")
  118. }
  119. func (s *DockerDaemonSuite) TestDaemonStartIptablesFalse(c *check.C) {
  120. if err := s.d.Start("--iptables=false"); err != nil {
  121. c.Fatalf("we should have been able to start the daemon with passing iptables=false: %v", err)
  122. }
  123. }
  124. // Issue #8444: If docker0 bridge is modified (intentionally or unintentionally) and
  125. // no longer has an IP associated, we should gracefully handle that case and associate
  126. // an IP with it rather than fail daemon start
  127. func (s *DockerDaemonSuite) TestDaemonStartBridgeWithoutIPAssociation(c *check.C) {
  128. // rather than depending on brctl commands to verify docker0 is created and up
  129. // let's start the daemon and stop it, and then make a modification to run the
  130. // actual test
  131. if err := s.d.Start(); err != nil {
  132. c.Fatalf("Could not start daemon: %v", err)
  133. }
  134. if err := s.d.Stop(); err != nil {
  135. c.Fatalf("Could not stop daemon: %v", err)
  136. }
  137. // now we will remove the ip from docker0 and then try starting the daemon
  138. ipCmd := exec.Command("ip", "addr", "flush", "dev", "docker0")
  139. stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
  140. if err != nil {
  141. c.Fatalf("failed to remove docker0 IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
  142. }
  143. if err := s.d.Start(); err != nil {
  144. warning := "**WARNING: Docker bridge network in bad state--delete docker0 bridge interface to fix"
  145. c.Fatalf("Could not start daemon when docker0 has no IP address: %v\n%s", err, warning)
  146. }
  147. }
  148. func (s *DockerDaemonSuite) TestDaemonIptablesClean(c *check.C) {
  149. if err := s.d.StartWithBusybox(); err != nil {
  150. c.Fatalf("Could not start daemon with busybox: %v", err)
  151. }
  152. if out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top"); err != nil {
  153. c.Fatalf("Could not run top: %s, %v", out, err)
  154. }
  155. // get output from iptables with container running
  156. ipTablesSearchString := "tcp dpt:80"
  157. ipTablesCmd := exec.Command("iptables", "-nvL")
  158. out, _, err := runCommandWithOutput(ipTablesCmd)
  159. if err != nil {
  160. c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
  161. }
  162. if !strings.Contains(out, ipTablesSearchString) {
  163. c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out)
  164. }
  165. if err := s.d.Stop(); err != nil {
  166. c.Fatalf("Could not stop daemon: %v", err)
  167. }
  168. // get output from iptables after restart
  169. ipTablesCmd = exec.Command("iptables", "-nvL")
  170. out, _, err = runCommandWithOutput(ipTablesCmd)
  171. if err != nil {
  172. c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
  173. }
  174. if strings.Contains(out, ipTablesSearchString) {
  175. c.Fatalf("iptables output should not have contained %q, but was %q", ipTablesSearchString, out)
  176. }
  177. }
  178. func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) {
  179. if err := s.d.StartWithBusybox(); err != nil {
  180. c.Fatalf("Could not start daemon with busybox: %v", err)
  181. }
  182. if out, err := s.d.Cmd("run", "-d", "--name", "top", "--restart=always", "-p", "80", "busybox:latest", "top"); err != nil {
  183. c.Fatalf("Could not run top: %s, %v", out, err)
  184. }
  185. // get output from iptables with container running
  186. ipTablesSearchString := "tcp dpt:80"
  187. ipTablesCmd := exec.Command("iptables", "-nvL")
  188. out, _, err := runCommandWithOutput(ipTablesCmd)
  189. if err != nil {
  190. c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
  191. }
  192. if !strings.Contains(out, ipTablesSearchString) {
  193. c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out)
  194. }
  195. if err := s.d.Restart(); err != nil {
  196. c.Fatalf("Could not restart daemon: %v", err)
  197. }
  198. // make sure the container is not running
  199. runningOut, err := s.d.Cmd("inspect", "--format='{{.State.Running}}'", "top")
  200. if err != nil {
  201. c.Fatalf("Could not inspect on container: %s, %v", out, err)
  202. }
  203. if strings.TrimSpace(runningOut) != "true" {
  204. c.Fatalf("Container should have been restarted after daemon restart. Status running should have been true but was: %q", strings.TrimSpace(runningOut))
  205. }
  206. // get output from iptables after restart
  207. ipTablesCmd = exec.Command("iptables", "-nvL")
  208. out, _, err = runCommandWithOutput(ipTablesCmd)
  209. if err != nil {
  210. c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
  211. }
  212. if !strings.Contains(out, ipTablesSearchString) {
  213. c.Fatalf("iptables output after restart should have contained %q, but was %q", ipTablesSearchString, out)
  214. }
  215. }
  216. // TestDaemonIPv6Enabled checks that when the daemon is started with --ipv6=true that the docker0 bridge
  217. // has the fe80::1 address and that a container is assigned a link-local address
  218. func (s *DockerSuite) TestDaemonIPv6Enabled(c *check.C) {
  219. testRequires(c, IPv6)
  220. if err := setupV6(); err != nil {
  221. c.Fatal("Could not set up host for IPv6 tests")
  222. }
  223. d := NewDaemon(c)
  224. if err := d.StartWithBusybox("--ipv6"); err != nil {
  225. c.Fatal(err)
  226. }
  227. defer d.Stop()
  228. iface, err := net.InterfaceByName("docker0")
  229. if err != nil {
  230. c.Fatalf("Error getting docker0 interface: %v", err)
  231. }
  232. addrs, err := iface.Addrs()
  233. if err != nil {
  234. c.Fatalf("Error getting addresses for docker0 interface: %v", err)
  235. }
  236. var found bool
  237. expected := "fe80::1/64"
  238. for i := range addrs {
  239. if addrs[i].String() == expected {
  240. found = true
  241. }
  242. }
  243. if !found {
  244. c.Fatalf("Bridge does not have an IPv6 Address")
  245. }
  246. if out, err := d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest"); err != nil {
  247. c.Fatalf("Could not run container: %s, %v", out, err)
  248. }
  249. out, err := d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.LinkLocalIPv6Address}}'", "ipv6test")
  250. out = strings.Trim(out, " \r\n'")
  251. if err != nil {
  252. c.Fatalf("Error inspecting container: %s, %v", out, err)
  253. }
  254. if ip := net.ParseIP(out); ip == nil {
  255. c.Fatalf("Container should have a link-local IPv6 address")
  256. }
  257. out, err = d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}'", "ipv6test")
  258. out = strings.Trim(out, " \r\n'")
  259. if err != nil {
  260. c.Fatalf("Error inspecting container: %s, %v", out, err)
  261. }
  262. if ip := net.ParseIP(out); ip != nil {
  263. c.Fatalf("Container should not have a global IPv6 address: %v", out)
  264. }
  265. if err := teardownV6(); err != nil {
  266. c.Fatal("Could not perform teardown for IPv6 tests")
  267. }
  268. }
  269. // TestDaemonIPv6FixedCIDR checks that when the daemon is started with --ipv6=true and a fixed CIDR
  270. // that running containers are given a link-local and global IPv6 address
  271. func (s *DockerSuite) TestDaemonIPv6FixedCIDR(c *check.C) {
  272. if err := setupV6(); err != nil {
  273. c.Fatal("Could not set up host for IPv6 tests")
  274. }
  275. d := NewDaemon(c)
  276. if err := d.StartWithBusybox("--ipv6", "--fixed-cidr-v6='2001:db8:2::/64'", "--default-gateway-v6='2001:db8:2::100'"); err != nil {
  277. c.Fatalf("Could not start daemon with busybox: %v", err)
  278. }
  279. defer d.Stop()
  280. if out, err := d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest"); err != nil {
  281. c.Fatalf("Could not run container: %s, %v", out, err)
  282. }
  283. out, err := d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}'", "ipv6test")
  284. out = strings.Trim(out, " \r\n'")
  285. if err != nil {
  286. c.Fatalf("Error inspecting container: %s, %v", out, err)
  287. }
  288. if ip := net.ParseIP(out); ip == nil {
  289. c.Fatalf("Container should have a global IPv6 address")
  290. }
  291. // TODO: Check IPv6 def gateway in inspect o/p (once docker/docker 19001 is merged
  292. if err := teardownV6(); err != nil {
  293. c.Fatal("Could not perform teardown for IPv6 tests")
  294. }
  295. }
  296. // TestDaemonIPv6FixedCIDRAndMac checks that when the daemon is started with ipv6 fixed CIDR
  297. // the running containers are given a an IPv6 address derived from the MAC address and the ipv6 fixed CIDR
  298. func (s *DockerSuite) TestDaemonIPv6FixedCIDRAndMac(c *check.C) {
  299. err := setupV6()
  300. c.Assert(err, checker.IsNil)
  301. d := NewDaemon(c)
  302. err = d.StartWithBusybox("--ipv6", "--fixed-cidr-v6='2001:db8:1::/64'")
  303. c.Assert(err, checker.IsNil)
  304. defer d.Stop()
  305. out, err := d.Cmd("run", "-itd", "--name=ipv6test", "--mac-address", "AA:BB:CC:DD:EE:FF", "busybox")
  306. c.Assert(err, checker.IsNil)
  307. out, err = d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}'", "ipv6test")
  308. c.Assert(err, checker.IsNil)
  309. c.Assert(strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:1::aabb:ccdd:eeff")
  310. err = teardownV6()
  311. c.Assert(err, checker.IsNil)
  312. }
  313. func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) {
  314. c.Assert(s.d.Start("--log-level=bogus"), check.NotNil, check.Commentf("Daemon shouldn't start with wrong log level"))
  315. }
  316. func (s *DockerSuite) TestDaemonStartWithDaemonCommand(c *check.C) {
  317. type kind int
  318. const (
  319. common kind = iota
  320. daemon
  321. )
  322. var flags = []map[kind][]string{
  323. {common: {"-l", "info"}, daemon: {"--selinux-enabled"}},
  324. {common: {"-D"}, daemon: {"--selinux-enabled", "-r"}},
  325. {common: {"-D"}, daemon: {"--restart"}},
  326. {common: {"--debug"}, daemon: {"--log-driver=json-file", "--log-opt=max-size=1k"}},
  327. }
  328. var invalidGlobalFlags = [][]string{
  329. //Invalid because you cannot pass daemon flags as global flags.
  330. {"--selinux-enabled", "-l", "info"},
  331. {"-D", "-r"},
  332. {"--config", "/tmp"},
  333. }
  334. // `docker daemon -l info --selinux-enabled`
  335. // should NOT error out
  336. for _, f := range flags {
  337. d := NewDaemon(c)
  338. args := append(f[common], f[daemon]...)
  339. if err := d.Start(args...); err != nil {
  340. c.Fatalf("Daemon should have started successfully with %v: %v", args, err)
  341. }
  342. d.Stop()
  343. }
  344. // `docker -l info daemon --selinux-enabled`
  345. // should error out
  346. for _, f := range flags {
  347. d := NewDaemon(c)
  348. d.GlobalFlags = f[common]
  349. if err := d.Start(f[daemon]...); err == nil {
  350. d.Stop()
  351. c.Fatalf("Daemon should have failed to start with docker %v daemon %v", d.GlobalFlags, f[daemon])
  352. }
  353. }
  354. for _, f := range invalidGlobalFlags {
  355. cmd := exec.Command(dockerBinary, append(f, "daemon")...)
  356. errch := make(chan error)
  357. var err error
  358. go func() {
  359. errch <- cmd.Run()
  360. }()
  361. select {
  362. case <-time.After(time.Second):
  363. cmd.Process.Kill()
  364. case err = <-errch:
  365. }
  366. if err == nil {
  367. c.Fatalf("Daemon should have failed to start with docker %v daemon", f)
  368. }
  369. }
  370. }
  371. func (s *DockerDaemonSuite) TestDaemonLogLevelDebug(c *check.C) {
  372. if err := s.d.Start("--log-level=debug"); err != nil {
  373. c.Fatal(err)
  374. }
  375. content, _ := ioutil.ReadFile(s.d.logFile.Name())
  376. if !strings.Contains(string(content), `level=debug`) {
  377. c.Fatalf(`Missing level="debug" in log file:\n%s`, string(content))
  378. }
  379. }
  380. func (s *DockerDaemonSuite) TestDaemonLogLevelFatal(c *check.C) {
  381. // we creating new daemons to create new logFile
  382. if err := s.d.Start("--log-level=fatal"); err != nil {
  383. c.Fatal(err)
  384. }
  385. content, _ := ioutil.ReadFile(s.d.logFile.Name())
  386. if strings.Contains(string(content), `level=debug`) {
  387. c.Fatalf(`Should not have level="debug" in log file:\n%s`, string(content))
  388. }
  389. }
  390. func (s *DockerDaemonSuite) TestDaemonFlagD(c *check.C) {
  391. if err := s.d.Start("-D"); err != nil {
  392. c.Fatal(err)
  393. }
  394. content, _ := ioutil.ReadFile(s.d.logFile.Name())
  395. if !strings.Contains(string(content), `level=debug`) {
  396. c.Fatalf(`Should have level="debug" in log file using -D:\n%s`, string(content))
  397. }
  398. }
  399. func (s *DockerDaemonSuite) TestDaemonFlagDebug(c *check.C) {
  400. if err := s.d.Start("--debug"); err != nil {
  401. c.Fatal(err)
  402. }
  403. content, _ := ioutil.ReadFile(s.d.logFile.Name())
  404. if !strings.Contains(string(content), `level=debug`) {
  405. c.Fatalf(`Should have level="debug" in log file using --debug:\n%s`, string(content))
  406. }
  407. }
  408. func (s *DockerDaemonSuite) TestDaemonFlagDebugLogLevelFatal(c *check.C) {
  409. if err := s.d.Start("--debug", "--log-level=fatal"); err != nil {
  410. c.Fatal(err)
  411. }
  412. content, _ := ioutil.ReadFile(s.d.logFile.Name())
  413. if !strings.Contains(string(content), `level=debug`) {
  414. c.Fatalf(`Should have level="debug" in log file when using both --debug and --log-level=fatal:\n%s`, string(content))
  415. }
  416. }
  417. func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *check.C) {
  418. listeningPorts := [][]string{
  419. {"0.0.0.0", "0.0.0.0", "5678"},
  420. {"127.0.0.1", "127.0.0.1", "1234"},
  421. {"localhost", "127.0.0.1", "1235"},
  422. }
  423. cmdArgs := make([]string, 0, len(listeningPorts)*2)
  424. for _, hostDirective := range listeningPorts {
  425. cmdArgs = append(cmdArgs, "--host", fmt.Sprintf("tcp://%s:%s", hostDirective[0], hostDirective[2]))
  426. }
  427. if err := s.d.StartWithBusybox(cmdArgs...); err != nil {
  428. c.Fatalf("Could not start daemon with busybox: %v", err)
  429. }
  430. for _, hostDirective := range listeningPorts {
  431. output, err := s.d.Cmd("run", "-p", fmt.Sprintf("%s:%s:80", hostDirective[1], hostDirective[2]), "busybox", "true")
  432. if err == nil {
  433. c.Fatalf("Container should not start, expected port already allocated error: %q", output)
  434. } else if !strings.Contains(output, "port is already allocated") {
  435. c.Fatalf("Expected port is already allocated error: %q", output)
  436. }
  437. }
  438. }
  439. func (s *DockerDaemonSuite) TestDaemonKeyGeneration(c *check.C) {
  440. // TODO: skip or update for Windows daemon
  441. os.Remove("/etc/docker/key.json")
  442. if err := s.d.Start(); err != nil {
  443. c.Fatalf("Could not start daemon: %v", err)
  444. }
  445. s.d.Stop()
  446. k, err := libtrust.LoadKeyFile("/etc/docker/key.json")
  447. if err != nil {
  448. c.Fatalf("Error opening key file")
  449. }
  450. kid := k.KeyID()
  451. // Test Key ID is a valid fingerprint (e.g. QQXN:JY5W:TBXI:MK3X:GX6P:PD5D:F56N:NHCS:LVRZ:JA46:R24J:XEFF)
  452. if len(kid) != 59 {
  453. c.Fatalf("Bad key ID: %s", kid)
  454. }
  455. }
  456. func (s *DockerDaemonSuite) TestDaemonKeyMigration(c *check.C) {
  457. // TODO: skip or update for Windows daemon
  458. os.Remove("/etc/docker/key.json")
  459. k1, err := libtrust.GenerateECP256PrivateKey()
  460. if err != nil {
  461. c.Fatalf("Error generating private key: %s", err)
  462. }
  463. if err := os.MkdirAll(filepath.Join(os.Getenv("HOME"), ".docker"), 0755); err != nil {
  464. c.Fatalf("Error creating .docker directory: %s", err)
  465. }
  466. if err := libtrust.SaveKey(filepath.Join(os.Getenv("HOME"), ".docker", "key.json"), k1); err != nil {
  467. c.Fatalf("Error saving private key: %s", err)
  468. }
  469. if err := s.d.Start(); err != nil {
  470. c.Fatalf("Could not start daemon: %v", err)
  471. }
  472. s.d.Stop()
  473. k2, err := libtrust.LoadKeyFile("/etc/docker/key.json")
  474. if err != nil {
  475. c.Fatalf("Error opening key file")
  476. }
  477. if k1.KeyID() != k2.KeyID() {
  478. c.Fatalf("Key not migrated")
  479. }
  480. }
  481. // GH#11320 - verify that the daemon exits on failure properly
  482. // Note that this explicitly tests the conflict of {-b,--bridge} and {--bip} options as the means
  483. // to get a daemon init failure; no other tests for -b/--bip conflict are therefore required
  484. func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) {
  485. //attempt to start daemon with incorrect flags (we know -b and --bip conflict)
  486. if err := s.d.Start("--bridge", "nosuchbridge", "--bip", "1.1.1.1"); err != nil {
  487. //verify we got the right error
  488. if !strings.Contains(err.Error(), "Daemon exited and never started") {
  489. c.Fatalf("Expected daemon not to start, got %v", err)
  490. }
  491. // look in the log and make sure we got the message that daemon is shutting down
  492. runCmd := exec.Command("grep", "Error starting daemon", s.d.LogfileName())
  493. if out, _, err := runCommandWithOutput(runCmd); err != nil {
  494. c.Fatalf("Expected 'Error starting daemon' message; but doesn't exist in log: %q, err: %v", out, err)
  495. }
  496. } else {
  497. //if we didn't get an error and the daemon is running, this is a failure
  498. c.Fatal("Conflicting options should cause the daemon to error out with a failure")
  499. }
  500. }
  501. func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
  502. d := s.d
  503. err := d.Start("--bridge", "nosuchbridge")
  504. c.Assert(err, check.NotNil, check.Commentf("--bridge option with an invalid bridge should cause the daemon to fail"))
  505. defer d.Restart()
  506. bridgeName := "external-bridge"
  507. bridgeIP := "192.169.1.1/24"
  508. _, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
  509. out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
  510. c.Assert(err, check.IsNil, check.Commentf(out))
  511. defer deleteInterface(c, bridgeName)
  512. err = d.StartWithBusybox("--bridge", bridgeName)
  513. c.Assert(err, check.IsNil)
  514. ipTablesSearchString := bridgeIPNet.String()
  515. ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
  516. out, _, err = runCommandWithOutput(ipTablesCmd)
  517. c.Assert(err, check.IsNil)
  518. c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true,
  519. check.Commentf("iptables output should have contained %q, but was %q",
  520. ipTablesSearchString, out))
  521. _, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top")
  522. c.Assert(err, check.IsNil)
  523. containerIP := d.findContainerIP("ExtContainer")
  524. ip := net.ParseIP(containerIP)
  525. c.Assert(bridgeIPNet.Contains(ip), check.Equals, true,
  526. check.Commentf("Container IP-Address must be in the same subnet range : %s",
  527. containerIP))
  528. }
  529. func createInterface(c *check.C, ifType string, ifName string, ipNet string) (string, error) {
  530. args := []string{"link", "add", "name", ifName, "type", ifType}
  531. ipLinkCmd := exec.Command("ip", args...)
  532. out, _, err := runCommandWithOutput(ipLinkCmd)
  533. if err != nil {
  534. return out, err
  535. }
  536. ifCfgCmd := exec.Command("ifconfig", ifName, ipNet, "up")
  537. out, _, err = runCommandWithOutput(ifCfgCmd)
  538. return out, err
  539. }
  540. func deleteInterface(c *check.C, ifName string) {
  541. ifCmd := exec.Command("ip", "link", "delete", ifName)
  542. out, _, err := runCommandWithOutput(ifCmd)
  543. c.Assert(err, check.IsNil, check.Commentf(out))
  544. flushCmd := exec.Command("iptables", "-t", "nat", "--flush")
  545. out, _, err = runCommandWithOutput(flushCmd)
  546. c.Assert(err, check.IsNil, check.Commentf(out))
  547. flushCmd = exec.Command("iptables", "--flush")
  548. out, _, err = runCommandWithOutput(flushCmd)
  549. c.Assert(err, check.IsNil, check.Commentf(out))
  550. }
  551. func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
  552. // TestDaemonBridgeIP Steps
  553. // 1. Delete the existing docker0 Bridge
  554. // 2. Set --bip daemon configuration and start the new Docker Daemon
  555. // 3. Check if the bip config has taken effect using ifconfig and iptables commands
  556. // 4. Launch a Container and make sure the IP-Address is in the expected subnet
  557. // 5. Delete the docker0 Bridge
  558. // 6. Restart the Docker Daemon (via deferred action)
  559. // This Restart takes care of bringing docker0 interface back to auto-assigned IP
  560. defaultNetworkBridge := "docker0"
  561. deleteInterface(c, defaultNetworkBridge)
  562. d := s.d
  563. bridgeIP := "192.169.1.1/24"
  564. ip, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
  565. err := d.StartWithBusybox("--bip", bridgeIP)
  566. c.Assert(err, check.IsNil)
  567. defer d.Restart()
  568. ifconfigSearchString := ip.String()
  569. ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge)
  570. out, _, _, err := runCommandWithStdoutStderr(ifconfigCmd)
  571. c.Assert(err, check.IsNil)
  572. c.Assert(strings.Contains(out, ifconfigSearchString), check.Equals, true,
  573. check.Commentf("ifconfig output should have contained %q, but was %q",
  574. ifconfigSearchString, out))
  575. ipTablesSearchString := bridgeIPNet.String()
  576. ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
  577. out, _, err = runCommandWithOutput(ipTablesCmd)
  578. c.Assert(err, check.IsNil)
  579. c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true,
  580. check.Commentf("iptables output should have contained %q, but was %q",
  581. ipTablesSearchString, out))
  582. out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top")
  583. c.Assert(err, check.IsNil)
  584. containerIP := d.findContainerIP("test")
  585. ip = net.ParseIP(containerIP)
  586. c.Assert(bridgeIPNet.Contains(ip), check.Equals, true,
  587. check.Commentf("Container IP-Address must be in the same subnet range : %s",
  588. containerIP))
  589. deleteInterface(c, defaultNetworkBridge)
  590. }
  591. func (s *DockerDaemonSuite) TestDaemonRestartWithBridgeIPChange(c *check.C) {
  592. if err := s.d.Start(); err != nil {
  593. c.Fatalf("Could not start daemon: %v", err)
  594. }
  595. defer s.d.Restart()
  596. if err := s.d.Stop(); err != nil {
  597. c.Fatalf("Could not stop daemon: %v", err)
  598. }
  599. // now we will change the docker0's IP and then try starting the daemon
  600. bridgeIP := "192.169.100.1/24"
  601. _, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
  602. ipCmd := exec.Command("ifconfig", "docker0", bridgeIP)
  603. stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
  604. if err != nil {
  605. c.Fatalf("failed to change docker0's IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
  606. }
  607. if err := s.d.Start("--bip", bridgeIP); err != nil {
  608. c.Fatalf("Could not start daemon: %v", err)
  609. }
  610. //check if the iptables contains new bridgeIP MASQUERADE rule
  611. ipTablesSearchString := bridgeIPNet.String()
  612. ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
  613. out, _, err := runCommandWithOutput(ipTablesCmd)
  614. if err != nil {
  615. c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
  616. }
  617. if !strings.Contains(out, ipTablesSearchString) {
  618. c.Fatalf("iptables output should have contained new MASQUERADE rule with IP %q, but was %q", ipTablesSearchString, out)
  619. }
  620. }
  621. func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) {
  622. d := s.d
  623. bridgeName := "external-bridge"
  624. bridgeIP := "192.169.1.1/24"
  625. out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
  626. c.Assert(err, check.IsNil, check.Commentf(out))
  627. defer deleteInterface(c, bridgeName)
  628. args := []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"}
  629. err = d.StartWithBusybox(args...)
  630. c.Assert(err, check.IsNil)
  631. defer d.Restart()
  632. for i := 0; i < 4; i++ {
  633. cName := "Container" + strconv.Itoa(i)
  634. out, err := d.Cmd("run", "-d", "--name", cName, "busybox", "top")
  635. if err != nil {
  636. c.Assert(strings.Contains(out, "no available IPv4 addresses"), check.Equals, true,
  637. check.Commentf("Could not run a Container : %s %s", err.Error(), out))
  638. }
  639. }
  640. }
  641. func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr2(c *check.C) {
  642. d := s.d
  643. bridgeName := "external-bridge"
  644. bridgeIP := "10.2.2.1/16"
  645. out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
  646. c.Assert(err, check.IsNil, check.Commentf(out))
  647. defer deleteInterface(c, bridgeName)
  648. err = d.StartWithBusybox("--bip", bridgeIP, "--fixed-cidr", "10.2.2.0/24")
  649. c.Assert(err, check.IsNil)
  650. defer s.d.Restart()
  651. out, err = d.Cmd("run", "-d", "--name", "bb", "busybox", "top")
  652. c.Assert(err, checker.IsNil, check.Commentf(out))
  653. defer d.Cmd("stop", "bb")
  654. out, err = d.Cmd("exec", "bb", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'")
  655. c.Assert(out, checker.Equals, "10.2.2.0\n")
  656. out, err = d.Cmd("run", "--rm", "busybox", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'")
  657. c.Assert(err, checker.IsNil, check.Commentf(out))
  658. c.Assert(out, checker.Equals, "10.2.2.2\n")
  659. }
  660. func (s *DockerDaemonSuite) TestDaemonBridgeFixedCIDREqualBridgeNetwork(c *check.C) {
  661. d := s.d
  662. bridgeName := "external-bridge"
  663. bridgeIP := "172.27.42.1/16"
  664. out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
  665. c.Assert(err, check.IsNil, check.Commentf(out))
  666. defer deleteInterface(c, bridgeName)
  667. err = d.StartWithBusybox("--bridge", bridgeName, "--fixed-cidr", bridgeIP)
  668. c.Assert(err, check.IsNil)
  669. defer s.d.Restart()
  670. out, err = d.Cmd("run", "-d", "busybox", "top")
  671. c.Assert(err, check.IsNil, check.Commentf(out))
  672. cid1 := strings.TrimSpace(out)
  673. defer d.Cmd("stop", cid1)
  674. }
  675. func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Implicit(c *check.C) {
  676. defaultNetworkBridge := "docker0"
  677. deleteInterface(c, defaultNetworkBridge)
  678. d := s.d
  679. bridgeIP := "192.169.1.1"
  680. bridgeIPNet := fmt.Sprintf("%s/24", bridgeIP)
  681. err := d.StartWithBusybox("--bip", bridgeIPNet)
  682. c.Assert(err, check.IsNil)
  683. defer d.Restart()
  684. expectedMessage := fmt.Sprintf("default via %s dev", bridgeIP)
  685. out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
  686. c.Assert(strings.Contains(out, expectedMessage), check.Equals, true,
  687. check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'",
  688. bridgeIP, strings.TrimSpace(out)))
  689. deleteInterface(c, defaultNetworkBridge)
  690. }
  691. func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Explicit(c *check.C) {
  692. defaultNetworkBridge := "docker0"
  693. deleteInterface(c, defaultNetworkBridge)
  694. d := s.d
  695. bridgeIP := "192.169.1.1"
  696. bridgeIPNet := fmt.Sprintf("%s/24", bridgeIP)
  697. gatewayIP := "192.169.1.254"
  698. err := d.StartWithBusybox("--bip", bridgeIPNet, "--default-gateway", gatewayIP)
  699. c.Assert(err, check.IsNil)
  700. defer d.Restart()
  701. expectedMessage := fmt.Sprintf("default via %s dev", gatewayIP)
  702. out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
  703. c.Assert(strings.Contains(out, expectedMessage), check.Equals, true,
  704. check.Commentf("Explicit default gateway should be %s, but default route was '%s'",
  705. gatewayIP, strings.TrimSpace(out)))
  706. deleteInterface(c, defaultNetworkBridge)
  707. }
  708. func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4ExplicitOutsideContainerSubnet(c *check.C) {
  709. defaultNetworkBridge := "docker0"
  710. deleteInterface(c, defaultNetworkBridge)
  711. // Program a custom default gateway outside of the container subnet, daemon should accept it and start
  712. err := s.d.StartWithBusybox("--bip", "172.16.0.10/16", "--fixed-cidr", "172.16.1.0/24", "--default-gateway", "172.16.0.254")
  713. c.Assert(err, check.IsNil)
  714. deleteInterface(c, defaultNetworkBridge)
  715. s.d.Restart()
  716. }
  717. func (s *DockerDaemonSuite) TestDaemonDefaultNetworkInvalidClusterConfig(c *check.C) {
  718. testRequires(c, DaemonIsLinux, SameHostDaemon)
  719. // Start daemon without docker0 bridge
  720. defaultNetworkBridge := "docker0"
  721. deleteInterface(c, defaultNetworkBridge)
  722. d := NewDaemon(c)
  723. discoveryBackend := "consul://consuladdr:consulport/some/path"
  724. err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend))
  725. c.Assert(err, checker.IsNil)
  726. // Start daemon with docker0 bridge
  727. ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge)
  728. _, err = runCommand(ifconfigCmd)
  729. c.Assert(err, check.IsNil)
  730. err = d.Restart(fmt.Sprintf("--cluster-store=%s", discoveryBackend))
  731. c.Assert(err, checker.IsNil)
  732. d.Stop()
  733. }
  734. func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
  735. d := s.d
  736. ipStr := "192.170.1.1/24"
  737. ip, _, _ := net.ParseCIDR(ipStr)
  738. args := []string{"--ip", ip.String()}
  739. err := d.StartWithBusybox(args...)
  740. c.Assert(err, check.IsNil)
  741. defer d.Restart()
  742. out, err := d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
  743. c.Assert(err, check.NotNil,
  744. check.Commentf("Running a container must fail with an invalid --ip option"))
  745. c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true)
  746. ifName := "dummy"
  747. out, err = createInterface(c, "dummy", ifName, ipStr)
  748. c.Assert(err, check.IsNil, check.Commentf(out))
  749. defer deleteInterface(c, ifName)
  750. _, err = d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
  751. c.Assert(err, check.IsNil)
  752. ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
  753. out, _, err = runCommandWithOutput(ipTablesCmd)
  754. c.Assert(err, check.IsNil)
  755. regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String())
  756. matched, _ := regexp.MatchString(regex, out)
  757. c.Assert(matched, check.Equals, true,
  758. check.Commentf("iptables output should have contained %q, but was %q", regex, out))
  759. }
  760. func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
  761. d := s.d
  762. bridgeName := "external-bridge"
  763. bridgeIP := "192.169.1.1/24"
  764. out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
  765. c.Assert(err, check.IsNil, check.Commentf(out))
  766. defer deleteInterface(c, bridgeName)
  767. args := []string{"--bridge", bridgeName, "--icc=false"}
  768. err = d.StartWithBusybox(args...)
  769. c.Assert(err, check.IsNil)
  770. defer d.Restart()
  771. ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD")
  772. out, _, err = runCommandWithOutput(ipTablesCmd)
  773. c.Assert(err, check.IsNil)
  774. regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
  775. matched, _ := regexp.MatchString(regex, out)
  776. c.Assert(matched, check.Equals, true,
  777. check.Commentf("iptables output should have contained %q, but was %q", regex, out))
  778. // Pinging another container must fail with --icc=false
  779. pingContainers(c, d, true)
  780. ipStr := "192.171.1.1/24"
  781. ip, _, _ := net.ParseCIDR(ipStr)
  782. ifName := "icc-dummy"
  783. createInterface(c, "dummy", ifName, ipStr)
  784. // But, Pinging external or a Host interface must succeed
  785. pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String())
  786. runArgs := []string{"--rm", "busybox", "sh", "-c", pingCmd}
  787. _, err = d.Cmd("run", runArgs...)
  788. c.Assert(err, check.IsNil)
  789. }
  790. func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) {
  791. d := s.d
  792. bridgeName := "external-bridge"
  793. bridgeIP := "192.169.1.1/24"
  794. out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
  795. c.Assert(err, check.IsNil, check.Commentf(out))
  796. defer deleteInterface(c, bridgeName)
  797. args := []string{"--bridge", bridgeName, "--icc=false"}
  798. err = d.StartWithBusybox(args...)
  799. c.Assert(err, check.IsNil)
  800. defer d.Restart()
  801. ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD")
  802. out, _, err = runCommandWithOutput(ipTablesCmd)
  803. c.Assert(err, check.IsNil)
  804. regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
  805. matched, _ := regexp.MatchString(regex, out)
  806. c.Assert(matched, check.Equals, true,
  807. check.Commentf("iptables output should have contained %q, but was %q", regex, out))
  808. out, err = d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567")
  809. c.Assert(err, check.IsNil, check.Commentf(out))
  810. out, err = d.Cmd("run", "--link", "icc1:icc1", "busybox", "nc", "icc1", "4567")
  811. c.Assert(err, check.IsNil, check.Commentf(out))
  812. }
  813. func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *check.C) {
  814. bridgeName := "external-bridge"
  815. bridgeIP := "192.169.1.1/24"
  816. out, err := createInterface(c, "bridge", bridgeName, bridgeIP)
  817. c.Assert(err, check.IsNil, check.Commentf(out))
  818. defer deleteInterface(c, bridgeName)
  819. err = s.d.StartWithBusybox("--bridge", bridgeName, "--icc=false")
  820. c.Assert(err, check.IsNil)
  821. defer s.d.Restart()
  822. _, err = s.d.Cmd("run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top")
  823. c.Assert(err, check.IsNil)
  824. _, err = s.d.Cmd("run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top")
  825. c.Assert(err, check.IsNil)
  826. childIP := s.d.findContainerIP("child")
  827. parentIP := s.d.findContainerIP("parent")
  828. sourceRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", childIP, "--sport", "80", "-d", parentIP, "-j", "ACCEPT"}
  829. destinationRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", parentIP, "--dport", "80", "-d", childIP, "-j", "ACCEPT"}
  830. if !iptables.Exists("filter", "DOCKER", sourceRule...) || !iptables.Exists("filter", "DOCKER", destinationRule...) {
  831. c.Fatal("Iptables rules not found")
  832. }
  833. s.d.Cmd("rm", "--link", "parent/http")
  834. if iptables.Exists("filter", "DOCKER", sourceRule...) || iptables.Exists("filter", "DOCKER", destinationRule...) {
  835. c.Fatal("Iptables rules should be removed when unlink")
  836. }
  837. s.d.Cmd("kill", "child")
  838. s.d.Cmd("kill", "parent")
  839. }
  840. func (s *DockerDaemonSuite) TestDaemonUlimitDefaults(c *check.C) {
  841. testRequires(c, DaemonIsLinux)
  842. if err := s.d.StartWithBusybox("--default-ulimit", "nofile=42:42", "--default-ulimit", "nproc=1024:1024"); err != nil {
  843. c.Fatal(err)
  844. }
  845. out, err := s.d.Cmd("run", "--ulimit", "nproc=2048", "--name=test", "busybox", "/bin/sh", "-c", "echo $(ulimit -n); echo $(ulimit -p)")
  846. if err != nil {
  847. c.Fatal(out, err)
  848. }
  849. outArr := strings.Split(out, "\n")
  850. if len(outArr) < 2 {
  851. c.Fatalf("got unexpected output: %s", out)
  852. }
  853. nofile := strings.TrimSpace(outArr[0])
  854. nproc := strings.TrimSpace(outArr[1])
  855. if nofile != "42" {
  856. c.Fatalf("expected `ulimit -n` to be `42`, got: %s", nofile)
  857. }
  858. if nproc != "2048" {
  859. c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc)
  860. }
  861. // Now restart daemon with a new default
  862. if err := s.d.Restart("--default-ulimit", "nofile=43"); err != nil {
  863. c.Fatal(err)
  864. }
  865. out, err = s.d.Cmd("start", "-a", "test")
  866. if err != nil {
  867. c.Fatal(err)
  868. }
  869. outArr = strings.Split(out, "\n")
  870. if len(outArr) < 2 {
  871. c.Fatalf("got unexpected output: %s", out)
  872. }
  873. nofile = strings.TrimSpace(outArr[0])
  874. nproc = strings.TrimSpace(outArr[1])
  875. if nofile != "43" {
  876. c.Fatalf("expected `ulimit -n` to be `43`, got: %s", nofile)
  877. }
  878. if nproc != "2048" {
  879. c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc)
  880. }
  881. }
  882. // #11315
  883. func (s *DockerDaemonSuite) TestDaemonRestartRenameContainer(c *check.C) {
  884. if err := s.d.StartWithBusybox(); err != nil {
  885. c.Fatal(err)
  886. }
  887. if out, err := s.d.Cmd("run", "--name=test", "busybox"); err != nil {
  888. c.Fatal(err, out)
  889. }
  890. if out, err := s.d.Cmd("rename", "test", "test2"); err != nil {
  891. c.Fatal(err, out)
  892. }
  893. if err := s.d.Restart(); err != nil {
  894. c.Fatal(err)
  895. }
  896. if out, err := s.d.Cmd("start", "test2"); err != nil {
  897. c.Fatal(err, out)
  898. }
  899. }
  900. func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefault(c *check.C) {
  901. if err := s.d.StartWithBusybox(); err != nil {
  902. c.Fatal(err)
  903. }
  904. out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline")
  905. if err != nil {
  906. c.Fatal(out, err)
  907. }
  908. id := strings.TrimSpace(out)
  909. if out, err := s.d.Cmd("wait", id); err != nil {
  910. c.Fatal(out, err)
  911. }
  912. logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log")
  913. if _, err := os.Stat(logPath); err != nil {
  914. c.Fatal(err)
  915. }
  916. f, err := os.Open(logPath)
  917. if err != nil {
  918. c.Fatal(err)
  919. }
  920. var res struct {
  921. Log string `json:"log"`
  922. Stream string `json:"stream"`
  923. Time time.Time `json:"time"`
  924. }
  925. if err := json.NewDecoder(f).Decode(&res); err != nil {
  926. c.Fatal(err)
  927. }
  928. if res.Log != "testline\n" {
  929. c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n")
  930. }
  931. if res.Stream != "stdout" {
  932. c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout")
  933. }
  934. if !time.Now().After(res.Time) {
  935. c.Fatalf("Log time %v in future", res.Time)
  936. }
  937. }
  938. func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefaultOverride(c *check.C) {
  939. if err := s.d.StartWithBusybox(); err != nil {
  940. c.Fatal(err)
  941. }
  942. out, err := s.d.Cmd("run", "-d", "--log-driver=none", "busybox", "echo", "testline")
  943. if err != nil {
  944. c.Fatal(out, err)
  945. }
  946. id := strings.TrimSpace(out)
  947. if out, err := s.d.Cmd("wait", id); err != nil {
  948. c.Fatal(out, err)
  949. }
  950. logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log")
  951. if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) {
  952. c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err)
  953. }
  954. }
  955. func (s *DockerDaemonSuite) TestDaemonLoggingDriverNone(c *check.C) {
  956. if err := s.d.StartWithBusybox("--log-driver=none"); err != nil {
  957. c.Fatal(err)
  958. }
  959. out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline")
  960. if err != nil {
  961. c.Fatal(out, err)
  962. }
  963. id := strings.TrimSpace(out)
  964. if out, err := s.d.Cmd("wait", id); err != nil {
  965. c.Fatal(out, err)
  966. }
  967. logPath := filepath.Join(s.d.folder, "graph", "containers", id, id+"-json.log")
  968. if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) {
  969. c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err)
  970. }
  971. }
  972. func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneOverride(c *check.C) {
  973. if err := s.d.StartWithBusybox("--log-driver=none"); err != nil {
  974. c.Fatal(err)
  975. }
  976. out, err := s.d.Cmd("run", "-d", "--log-driver=json-file", "busybox", "echo", "testline")
  977. if err != nil {
  978. c.Fatal(out, err)
  979. }
  980. id := strings.TrimSpace(out)
  981. if out, err := s.d.Cmd("wait", id); err != nil {
  982. c.Fatal(out, err)
  983. }
  984. logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log")
  985. if _, err := os.Stat(logPath); err != nil {
  986. c.Fatal(err)
  987. }
  988. f, err := os.Open(logPath)
  989. if err != nil {
  990. c.Fatal(err)
  991. }
  992. var res struct {
  993. Log string `json:"log"`
  994. Stream string `json:"stream"`
  995. Time time.Time `json:"time"`
  996. }
  997. if err := json.NewDecoder(f).Decode(&res); err != nil {
  998. c.Fatal(err)
  999. }
  1000. if res.Log != "testline\n" {
  1001. c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n")
  1002. }
  1003. if res.Stream != "stdout" {
  1004. c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout")
  1005. }
  1006. if !time.Now().After(res.Time) {
  1007. c.Fatalf("Log time %v in future", res.Time)
  1008. }
  1009. }
  1010. func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) {
  1011. if err := s.d.StartWithBusybox("--log-driver=none"); err != nil {
  1012. c.Fatal(err)
  1013. }
  1014. out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline")
  1015. if err != nil {
  1016. c.Fatal(out, err)
  1017. }
  1018. id := strings.TrimSpace(out)
  1019. out, err = s.d.Cmd("logs", id)
  1020. if err == nil {
  1021. c.Fatalf("Logs should fail with 'none' driver")
  1022. }
  1023. if !strings.Contains(out, `"logs" command is supported only for "json-file" and "journald" logging drivers (got: none)`) {
  1024. c.Fatalf("There should be an error about none not being a recognized log driver, got: %s", out)
  1025. }
  1026. }
  1027. func (s *DockerDaemonSuite) TestDaemonDots(c *check.C) {
  1028. if err := s.d.StartWithBusybox(); err != nil {
  1029. c.Fatal(err)
  1030. }
  1031. // Now create 4 containers
  1032. if _, err := s.d.Cmd("create", "busybox"); err != nil {
  1033. c.Fatalf("Error creating container: %q", err)
  1034. }
  1035. if _, err := s.d.Cmd("create", "busybox"); err != nil {
  1036. c.Fatalf("Error creating container: %q", err)
  1037. }
  1038. if _, err := s.d.Cmd("create", "busybox"); err != nil {
  1039. c.Fatalf("Error creating container: %q", err)
  1040. }
  1041. if _, err := s.d.Cmd("create", "busybox"); err != nil {
  1042. c.Fatalf("Error creating container: %q", err)
  1043. }
  1044. s.d.Stop()
  1045. s.d.Start("--log-level=debug")
  1046. s.d.Stop()
  1047. content, _ := ioutil.ReadFile(s.d.logFile.Name())
  1048. if strings.Contains(string(content), "....") {
  1049. c.Fatalf("Debug level should not have ....\n%s", string(content))
  1050. }
  1051. s.d.Start("--log-level=error")
  1052. s.d.Stop()
  1053. content, _ = ioutil.ReadFile(s.d.logFile.Name())
  1054. if strings.Contains(string(content), "....") {
  1055. c.Fatalf("Error level should not have ....\n%s", string(content))
  1056. }
  1057. s.d.Start("--log-level=info")
  1058. s.d.Stop()
  1059. content, _ = ioutil.ReadFile(s.d.logFile.Name())
  1060. if !strings.Contains(string(content), "....") {
  1061. c.Fatalf("Info level should have ....\n%s", string(content))
  1062. }
  1063. }
  1064. func (s *DockerDaemonSuite) TestDaemonUnixSockCleanedUp(c *check.C) {
  1065. dir, err := ioutil.TempDir("", "socket-cleanup-test")
  1066. if err != nil {
  1067. c.Fatal(err)
  1068. }
  1069. defer os.RemoveAll(dir)
  1070. sockPath := filepath.Join(dir, "docker.sock")
  1071. if err := s.d.Start("--host", "unix://"+sockPath); err != nil {
  1072. c.Fatal(err)
  1073. }
  1074. if _, err := os.Stat(sockPath); err != nil {
  1075. c.Fatal("socket does not exist")
  1076. }
  1077. if err := s.d.Stop(); err != nil {
  1078. c.Fatal(err)
  1079. }
  1080. if _, err := os.Stat(sockPath); err == nil || !os.IsNotExist(err) {
  1081. c.Fatal("unix socket is not cleaned up")
  1082. }
  1083. }
  1084. func (s *DockerDaemonSuite) TestDaemonWithWrongkey(c *check.C) {
  1085. type Config struct {
  1086. Crv string `json:"crv"`
  1087. D string `json:"d"`
  1088. Kid string `json:"kid"`
  1089. Kty string `json:"kty"`
  1090. X string `json:"x"`
  1091. Y string `json:"y"`
  1092. }
  1093. os.Remove("/etc/docker/key.json")
  1094. if err := s.d.Start(); err != nil {
  1095. c.Fatalf("Failed to start daemon: %v", err)
  1096. }
  1097. if err := s.d.Stop(); err != nil {
  1098. c.Fatalf("Could not stop daemon: %v", err)
  1099. }
  1100. config := &Config{}
  1101. bytes, err := ioutil.ReadFile("/etc/docker/key.json")
  1102. if err != nil {
  1103. c.Fatalf("Error reading key.json file: %s", err)
  1104. }
  1105. // byte[] to Data-Struct
  1106. if err := json.Unmarshal(bytes, &config); err != nil {
  1107. c.Fatalf("Error Unmarshal: %s", err)
  1108. }
  1109. //replace config.Kid with the fake value
  1110. config.Kid = "VSAJ:FUYR:X3H2:B2VZ:KZ6U:CJD5:K7BX:ZXHY:UZXT:P4FT:MJWG:HRJ4"
  1111. // NEW Data-Struct to byte[]
  1112. newBytes, err := json.Marshal(&config)
  1113. if err != nil {
  1114. c.Fatalf("Error Marshal: %s", err)
  1115. }
  1116. // write back
  1117. if err := ioutil.WriteFile("/etc/docker/key.json", newBytes, 0400); err != nil {
  1118. c.Fatalf("Error ioutil.WriteFile: %s", err)
  1119. }
  1120. defer os.Remove("/etc/docker/key.json")
  1121. if err := s.d.Start(); err == nil {
  1122. c.Fatalf("It should not be successful to start daemon with wrong key: %v", err)
  1123. }
  1124. content, _ := ioutil.ReadFile(s.d.logFile.Name())
  1125. if !strings.Contains(string(content), "Public Key ID does not match") {
  1126. c.Fatal("Missing KeyID message from daemon logs")
  1127. }
  1128. }
  1129. func (s *DockerDaemonSuite) TestDaemonRestartKillWait(c *check.C) {
  1130. if err := s.d.StartWithBusybox(); err != nil {
  1131. c.Fatalf("Could not start daemon with busybox: %v", err)
  1132. }
  1133. out, err := s.d.Cmd("run", "-id", "busybox", "/bin/cat")
  1134. if err != nil {
  1135. c.Fatalf("Could not run /bin/cat: err=%v\n%s", err, out)
  1136. }
  1137. containerID := strings.TrimSpace(out)
  1138. if out, err := s.d.Cmd("kill", containerID); err != nil {
  1139. c.Fatalf("Could not kill %s: err=%v\n%s", containerID, err, out)
  1140. }
  1141. if err := s.d.Restart(); err != nil {
  1142. c.Fatalf("Could not restart daemon: %v", err)
  1143. }
  1144. errchan := make(chan error)
  1145. go func() {
  1146. if out, err := s.d.Cmd("wait", containerID); err != nil {
  1147. errchan <- fmt.Errorf("%v:\n%s", err, out)
  1148. }
  1149. close(errchan)
  1150. }()
  1151. select {
  1152. case <-time.After(5 * time.Second):
  1153. c.Fatal("Waiting on a stopped (killed) container timed out")
  1154. case err := <-errchan:
  1155. if err != nil {
  1156. c.Fatal(err)
  1157. }
  1158. }
  1159. }
  1160. // TestHttpsInfo connects via two-way authenticated HTTPS to the info endpoint
  1161. func (s *DockerDaemonSuite) TestHttpsInfo(c *check.C) {
  1162. const (
  1163. testDaemonHTTPSAddr = "tcp://localhost:4271"
  1164. )
  1165. if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem",
  1166. "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil {
  1167. c.Fatalf("Could not start daemon with busybox: %v", err)
  1168. }
  1169. daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"}
  1170. out, err := s.d.CmdWithArgs(daemonArgs, "info")
  1171. if err != nil {
  1172. c.Fatalf("Error Occurred: %s and output: %s", err, out)
  1173. }
  1174. }
  1175. // TestTlsVerify verifies that --tlsverify=false turns on tls
  1176. func (s *DockerDaemonSuite) TestTlsVerify(c *check.C) {
  1177. out, err := exec.Command(dockerBinary, "daemon", "--tlsverify=false").CombinedOutput()
  1178. if err == nil || !strings.Contains(string(out), "Could not load X509 key pair") {
  1179. c.Fatalf("Daemon should not have started due to missing certs: %v\n%s", err, string(out))
  1180. }
  1181. }
  1182. // TestHttpsInfoRogueCert connects via two-way authenticated HTTPS to the info endpoint
  1183. // by using a rogue client certificate and checks that it fails with the expected error.
  1184. func (s *DockerDaemonSuite) TestHttpsInfoRogueCert(c *check.C) {
  1185. const (
  1186. errBadCertificate = "remote error: bad certificate"
  1187. testDaemonHTTPSAddr = "tcp://localhost:4271"
  1188. )
  1189. if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem",
  1190. "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil {
  1191. c.Fatalf("Could not start daemon with busybox: %v", err)
  1192. }
  1193. daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
  1194. out, err := s.d.CmdWithArgs(daemonArgs, "info")
  1195. if err == nil || !strings.Contains(out, errBadCertificate) {
  1196. c.Fatalf("Expected err: %s, got instead: %s and output: %s", errBadCertificate, err, out)
  1197. }
  1198. }
  1199. // TestHttpsInfoRogueServerCert connects via two-way authenticated HTTPS to the info endpoint
  1200. // which provides a rogue server certificate and checks that it fails with the expected error
  1201. func (s *DockerDaemonSuite) TestHttpsInfoRogueServerCert(c *check.C) {
  1202. const (
  1203. errCaUnknown = "x509: certificate signed by unknown authority"
  1204. testDaemonRogueHTTPSAddr = "tcp://localhost:4272"
  1205. )
  1206. if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-rogue-cert.pem",
  1207. "--tlskey", "fixtures/https/server-rogue-key.pem", "-H", testDaemonRogueHTTPSAddr); err != nil {
  1208. c.Fatalf("Could not start daemon with busybox: %v", err)
  1209. }
  1210. daemonArgs := []string{"--host", testDaemonRogueHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"}
  1211. out, err := s.d.CmdWithArgs(daemonArgs, "info")
  1212. if err == nil || !strings.Contains(out, errCaUnknown) {
  1213. c.Fatalf("Expected err: %s, got instead: %s and output: %s", errCaUnknown, err, out)
  1214. }
  1215. }
  1216. func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
  1217. var dargs []string
  1218. if d != nil {
  1219. dargs = []string{"--host", d.sock()}
  1220. }
  1221. args := append(dargs, "run", "-d", "--name", "container1", "busybox", "top")
  1222. dockerCmd(c, args...)
  1223. args = append(dargs, "run", "--rm", "--link", "container1:alias1", "busybox", "sh", "-c")
  1224. pingCmd := "ping -c 1 %s -W 1"
  1225. args = append(args, fmt.Sprintf(pingCmd, "alias1"))
  1226. _, _, err := dockerCmdWithError(args...)
  1227. if expectFailure {
  1228. c.Assert(err, check.NotNil)
  1229. } else {
  1230. c.Assert(err, check.IsNil)
  1231. }
  1232. args = append(dargs, "rm", "-f", "container1")
  1233. dockerCmd(c, args...)
  1234. }
  1235. func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) {
  1236. c.Assert(s.d.StartWithBusybox(), check.IsNil)
  1237. socket := filepath.Join(s.d.folder, "docker.sock")
  1238. out, err := s.d.Cmd("run", "-d", "--restart=always", "-v", socket+":/sock", "busybox")
  1239. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  1240. c.Assert(s.d.Restart(), check.IsNil)
  1241. }
  1242. func (s *DockerDaemonSuite) TestCleanupMountsAfterCrash(c *check.C) {
  1243. c.Assert(s.d.StartWithBusybox(), check.IsNil)
  1244. out, err := s.d.Cmd("run", "-d", "busybox", "top")
  1245. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  1246. id := strings.TrimSpace(out)
  1247. c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil)
  1248. c.Assert(s.d.Start(), check.IsNil)
  1249. mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
  1250. c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
  1251. comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
  1252. c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment)
  1253. }
  1254. func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) {
  1255. testRequires(c, DaemonIsLinux, NotUserNamespace)
  1256. c.Assert(s.d.StartWithBusybox("-b", "none"), check.IsNil)
  1257. out, err := s.d.Cmd("run", "--rm", "busybox", "ip", "l")
  1258. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  1259. c.Assert(strings.Contains(out, "eth0"), check.Equals, false,
  1260. check.Commentf("There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled: %s", out))
  1261. out, err = s.d.Cmd("run", "--rm", "--net=bridge", "busybox", "ip", "l")
  1262. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  1263. c.Assert(strings.Contains(out, "eth0"), check.Equals, false,
  1264. check.Commentf("There shouldn't be eth0 in container in bridge mode when bridge network is disabled: %s", out))
  1265. // the extra grep and awk clean up the output of `ip` to only list the number and name of
  1266. // interfaces, allowing for different versions of ip (e.g. inside and outside the container) to
  1267. // be used while still verifying that the interface list is the exact same
  1268. cmd := exec.Command("sh", "-c", "ip l | grep -E '^[0-9]+:' | awk -F: ' { print $1\":\"$2 } '")
  1269. stdout := bytes.NewBuffer(nil)
  1270. cmd.Stdout = stdout
  1271. if err := cmd.Run(); err != nil {
  1272. c.Fatal("Failed to get host network interface")
  1273. }
  1274. out, err = s.d.Cmd("run", "--rm", "--net=host", "busybox", "sh", "-c", "ip l | grep -E '^[0-9]+:' | awk -F: ' { print $1\":\"$2 } '")
  1275. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  1276. c.Assert(out, check.Equals, fmt.Sprintf("%s", stdout),
  1277. check.Commentf("The network interfaces in container should be the same with host when --net=host when bridge network is disabled: %s", out))
  1278. }
  1279. func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) {
  1280. if err := s.d.StartWithBusybox(); err != nil {
  1281. t.Fatal(err)
  1282. }
  1283. if out, err := s.d.Cmd("run", "-ti", "-d", "--name", "test", "busybox"); err != nil {
  1284. t.Fatal(out, err)
  1285. }
  1286. if err := s.d.Restart(); err != nil {
  1287. t.Fatal(err)
  1288. }
  1289. // Container 'test' should be removed without error
  1290. if out, err := s.d.Cmd("rm", "test"); err != nil {
  1291. t.Fatal(out, err)
  1292. }
  1293. }
  1294. func (s *DockerDaemonSuite) TestDaemonRestartCleanupNetns(c *check.C) {
  1295. if err := s.d.StartWithBusybox(); err != nil {
  1296. c.Fatal(err)
  1297. }
  1298. out, err := s.d.Cmd("run", "--name", "netns", "-d", "busybox", "top")
  1299. if err != nil {
  1300. c.Fatal(out, err)
  1301. }
  1302. // Get sandbox key via inspect
  1303. out, err = s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.SandboxKey}}'", "netns")
  1304. if err != nil {
  1305. c.Fatalf("Error inspecting container: %s, %v", out, err)
  1306. }
  1307. fileName := strings.Trim(out, " \r\n'")
  1308. if out, err := s.d.Cmd("stop", "netns"); err != nil {
  1309. c.Fatal(out, err)
  1310. }
  1311. // Test if the file still exists
  1312. out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName))
  1313. out = strings.TrimSpace(out)
  1314. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  1315. c.Assert(out, check.Equals, fileName, check.Commentf("Output: %s", out))
  1316. // Remove the container and restart the daemon
  1317. if out, err := s.d.Cmd("rm", "netns"); err != nil {
  1318. c.Fatal(out, err)
  1319. }
  1320. if err := s.d.Restart(); err != nil {
  1321. c.Fatal(err)
  1322. }
  1323. // Test again and see now the netns file does not exist
  1324. out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName))
  1325. out = strings.TrimSpace(out)
  1326. c.Assert(err, check.Not(check.IsNil), check.Commentf("Output: %s", out))
  1327. }
  1328. // tests regression detailed in #13964 where DOCKER_TLS_VERIFY env is ignored
  1329. func (s *DockerDaemonSuite) TestDaemonNoTlsCliTlsVerifyWithEnv(c *check.C) {
  1330. host := "tcp://localhost:4271"
  1331. c.Assert(s.d.Start("-H", host), check.IsNil)
  1332. cmd := exec.Command(dockerBinary, "-H", host, "info")
  1333. cmd.Env = []string{"DOCKER_TLS_VERIFY=1", "DOCKER_CERT_PATH=fixtures/https"}
  1334. out, _, err := runCommandWithOutput(cmd)
  1335. c.Assert(err, check.Not(check.IsNil), check.Commentf("%s", out))
  1336. c.Assert(strings.Contains(out, "error occurred trying to connect"), check.Equals, true)
  1337. }
  1338. func setupV6() error {
  1339. // Hack to get the right IPv6 address on docker0, which has already been created
  1340. err := exec.Command("ip", "addr", "add", "fe80::1/64", "dev", "docker0").Run()
  1341. if err != nil {
  1342. return err
  1343. }
  1344. return nil
  1345. }
  1346. func teardownV6() error {
  1347. err := exec.Command("ip", "addr", "del", "fe80::1/64", "dev", "docker0").Run()
  1348. if err != nil {
  1349. return err
  1350. }
  1351. return nil
  1352. }
  1353. func (s *DockerDaemonSuite) TestDaemonRestartWithContainerWithRestartPolicyAlways(c *check.C) {
  1354. c.Assert(s.d.StartWithBusybox(), check.IsNil)
  1355. out, err := s.d.Cmd("run", "-d", "--restart", "always", "busybox", "top")
  1356. c.Assert(err, check.IsNil)
  1357. id := strings.TrimSpace(out)
  1358. _, err = s.d.Cmd("stop", id)
  1359. c.Assert(err, check.IsNil)
  1360. _, err = s.d.Cmd("wait", id)
  1361. c.Assert(err, check.IsNil)
  1362. out, err = s.d.Cmd("ps", "-q")
  1363. c.Assert(err, check.IsNil)
  1364. c.Assert(out, check.Equals, "")
  1365. c.Assert(s.d.Restart(), check.IsNil)
  1366. out, err = s.d.Cmd("ps", "-q")
  1367. c.Assert(err, check.IsNil)
  1368. c.Assert(strings.TrimSpace(out), check.Equals, id[:12])
  1369. }
  1370. func (s *DockerDaemonSuite) TestDaemonWideLogConfig(c *check.C) {
  1371. if err := s.d.StartWithBusybox("--log-driver=json-file", "--log-opt=max-size=1k"); err != nil {
  1372. c.Fatal(err)
  1373. }
  1374. out, err := s.d.Cmd("run", "-d", "--name=logtest", "busybox", "top")
  1375. c.Assert(err, check.IsNil, check.Commentf("Output: %s, err: %v", out, err))
  1376. out, err = s.d.Cmd("inspect", "-f", "{{ .HostConfig.LogConfig.Config }}", "logtest")
  1377. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  1378. cfg := strings.TrimSpace(out)
  1379. if cfg != "map[max-size:1k]" {
  1380. c.Fatalf("Unexpected log-opt: %s, expected map[max-size:1k]", cfg)
  1381. }
  1382. }
  1383. func (s *DockerDaemonSuite) TestDaemonRestartWithPausedContainer(c *check.C) {
  1384. if err := s.d.StartWithBusybox(); err != nil {
  1385. c.Fatal(err)
  1386. }
  1387. if out, err := s.d.Cmd("run", "-i", "-d", "--name", "test", "busybox", "top"); err != nil {
  1388. c.Fatal(err, out)
  1389. }
  1390. if out, err := s.d.Cmd("pause", "test"); err != nil {
  1391. c.Fatal(err, out)
  1392. }
  1393. if err := s.d.Restart(); err != nil {
  1394. c.Fatal(err)
  1395. }
  1396. errchan := make(chan error)
  1397. go func() {
  1398. out, err := s.d.Cmd("start", "test")
  1399. if err != nil {
  1400. errchan <- fmt.Errorf("%v:\n%s", err, out)
  1401. }
  1402. name := strings.TrimSpace(out)
  1403. if name != "test" {
  1404. errchan <- fmt.Errorf("Paused container start error on docker daemon restart, expected 'test' but got '%s'", name)
  1405. }
  1406. close(errchan)
  1407. }()
  1408. select {
  1409. case <-time.After(5 * time.Second):
  1410. c.Fatal("Waiting on start a container timed out")
  1411. case err := <-errchan:
  1412. if err != nil {
  1413. c.Fatal(err)
  1414. }
  1415. }
  1416. }
  1417. func (s *DockerDaemonSuite) TestDaemonRestartRmVolumeInUse(c *check.C) {
  1418. c.Assert(s.d.StartWithBusybox(), check.IsNil)
  1419. out, err := s.d.Cmd("create", "-v", "test:/foo", "busybox")
  1420. c.Assert(err, check.IsNil, check.Commentf(out))
  1421. c.Assert(s.d.Restart(), check.IsNil)
  1422. out, err = s.d.Cmd("volume", "rm", "test")
  1423. c.Assert(err, check.NotNil, check.Commentf("should not be able to remove in use volume after daemon restart"))
  1424. c.Assert(out, checker.Contains, "in use")
  1425. }
  1426. func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *check.C) {
  1427. c.Assert(s.d.Start(), check.IsNil)
  1428. _, err := s.d.Cmd("volume", "create", "--name", "test")
  1429. c.Assert(err, check.IsNil)
  1430. c.Assert(s.d.Restart(), check.IsNil)
  1431. _, err = s.d.Cmd("volume", "inspect", "test")
  1432. c.Assert(err, check.IsNil)
  1433. }
  1434. func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) {
  1435. for _, driver := range []string{
  1436. "syslog",
  1437. "gelf",
  1438. } {
  1439. args := []string{"--log-driver=" + driver, "--log-opt", driver + "-address=corrupted:42"}
  1440. c.Assert(s.d.Start(args...), check.NotNil, check.Commentf(fmt.Sprintf("Expected daemon not to start with invalid %s-address provided", driver)))
  1441. expected := fmt.Sprintf("Failed to set log opts: %s-address should be in form proto://address", driver)
  1442. runCmd := exec.Command("grep", expected, s.d.LogfileName())
  1443. if out, _, err := runCommandWithOutput(runCmd); err != nil {
  1444. c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err)
  1445. }
  1446. }
  1447. }
  1448. func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *check.C) {
  1449. c.Assert(s.d.Start("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil)
  1450. expected := "Failed to set log opts: invalid fluentd-address corrupted:c: "
  1451. runCmd := exec.Command("grep", expected, s.d.LogfileName())
  1452. if out, _, err := runCommandWithOutput(runCmd); err != nil {
  1453. c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err)
  1454. }
  1455. }
  1456. func (s *DockerDaemonSuite) TestDaemonStartWithoutHost(c *check.C) {
  1457. s.d.useDefaultHost = true
  1458. defer func() {
  1459. s.d.useDefaultHost = false
  1460. }()
  1461. c.Assert(s.d.Start(), check.IsNil)
  1462. }
  1463. func (s *DockerDaemonSuite) TestDaemonStartWithDefalutTlsHost(c *check.C) {
  1464. s.d.useDefaultTLSHost = true
  1465. defer func() {
  1466. s.d.useDefaultTLSHost = false
  1467. }()
  1468. if err := s.d.Start(
  1469. "--tlsverify",
  1470. "--tlscacert", "fixtures/https/ca.pem",
  1471. "--tlscert", "fixtures/https/server-cert.pem",
  1472. "--tlskey", "fixtures/https/server-key.pem"); err != nil {
  1473. c.Fatalf("Could not start daemon: %v", err)
  1474. }
  1475. // The client with --tlsverify should also use default host localhost:2376
  1476. tmpHost := os.Getenv("DOCKER_HOST")
  1477. defer func() {
  1478. os.Setenv("DOCKER_HOST", tmpHost)
  1479. }()
  1480. os.Setenv("DOCKER_HOST", "")
  1481. out, _ := dockerCmd(
  1482. c,
  1483. "--tlsverify",
  1484. "--tlscacert", "fixtures/https/ca.pem",
  1485. "--tlscert", "fixtures/https/client-cert.pem",
  1486. "--tlskey", "fixtures/https/client-key.pem",
  1487. "version",
  1488. )
  1489. if !strings.Contains(out, "Server") {
  1490. c.Fatalf("docker version should return information of server side")
  1491. }
  1492. }
  1493. func (s *DockerDaemonSuite) TestBridgeIPIsExcludedFromAllocatorPool(c *check.C) {
  1494. defaultNetworkBridge := "docker0"
  1495. deleteInterface(c, defaultNetworkBridge)
  1496. bridgeIP := "192.169.1.1"
  1497. bridgeRange := bridgeIP + "/30"
  1498. err := s.d.StartWithBusybox("--bip", bridgeRange)
  1499. c.Assert(err, check.IsNil)
  1500. defer s.d.Restart()
  1501. var cont int
  1502. for {
  1503. contName := fmt.Sprintf("container%d", cont)
  1504. _, err = s.d.Cmd("run", "--name", contName, "-d", "busybox", "/bin/sleep", "2")
  1505. if err != nil {
  1506. // pool exhausted
  1507. break
  1508. }
  1509. ip, err := s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.IPAddress}}'", contName)
  1510. c.Assert(err, check.IsNil)
  1511. c.Assert(ip, check.Not(check.Equals), bridgeIP)
  1512. cont++
  1513. }
  1514. }
  1515. // Test daemon for no space left on device error
  1516. func (s *DockerDaemonSuite) TestDaemonNoSpaceleftOnDeviceError(c *check.C) {
  1517. testRequires(c, SameHostDaemon, DaemonIsLinux)
  1518. // create a 2MiB image and mount it as graph root
  1519. cmd := exec.Command("dd", "of=/tmp/testfs.img", "bs=1M", "seek=2", "count=0")
  1520. if err := cmd.Run(); err != nil {
  1521. c.Fatalf("dd failed: %v", err)
  1522. }
  1523. cmd = exec.Command("mkfs.ext4", "-F", "/tmp/testfs.img")
  1524. if err := cmd.Run(); err != nil {
  1525. c.Fatalf("mkfs.ext4 failed: %v", err)
  1526. }
  1527. cmd = exec.Command("mkdir", "-p", "/tmp/testfs-mount")
  1528. if err := cmd.Run(); err != nil {
  1529. c.Fatalf("mkdir failed: %v", err)
  1530. }
  1531. cmd = exec.Command("mount", "-t", "ext4", "-no", "loop,rw", "/tmp/testfs.img", "/tmp/testfs-mount")
  1532. if err := cmd.Run(); err != nil {
  1533. c.Fatalf("mount failed: %v", err)
  1534. }
  1535. err := s.d.Start("--graph", "/tmp/testfs-mount")
  1536. c.Assert(err, check.IsNil)
  1537. // pull a repository large enough to fill the mount point
  1538. out, err := s.d.Cmd("pull", "registry:2")
  1539. c.Assert(out, check.Not(check.Equals), 1, check.Commentf("no space left on device"))
  1540. }
  1541. // Test daemon restart with container links + auto restart
  1542. func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *check.C) {
  1543. d := NewDaemon(c)
  1544. err := d.StartWithBusybox()
  1545. c.Assert(err, checker.IsNil)
  1546. parent1Args := []string{}
  1547. parent2Args := []string{}
  1548. wg := sync.WaitGroup{}
  1549. maxChildren := 10
  1550. chErr := make(chan error, maxChildren)
  1551. for i := 0; i < maxChildren; i++ {
  1552. wg.Add(1)
  1553. name := fmt.Sprintf("test%d", i)
  1554. if i < maxChildren/2 {
  1555. parent1Args = append(parent1Args, []string{"--link", name}...)
  1556. } else {
  1557. parent2Args = append(parent2Args, []string{"--link", name}...)
  1558. }
  1559. go func() {
  1560. _, err = d.Cmd("run", "-d", "--name", name, "--restart=always", "busybox", "top")
  1561. chErr <- err
  1562. wg.Done()
  1563. }()
  1564. }
  1565. wg.Wait()
  1566. close(chErr)
  1567. for err := range chErr {
  1568. c.Assert(err, check.IsNil)
  1569. }
  1570. parent1Args = append([]string{"run", "-d"}, parent1Args...)
  1571. parent1Args = append(parent1Args, []string{"--name=parent1", "--restart=always", "busybox", "top"}...)
  1572. parent2Args = append([]string{"run", "-d"}, parent2Args...)
  1573. parent2Args = append(parent2Args, []string{"--name=parent2", "--restart=always", "busybox", "top"}...)
  1574. _, err = d.Cmd(parent1Args[0], parent1Args[1:]...)
  1575. c.Assert(err, check.IsNil)
  1576. _, err = d.Cmd(parent2Args[0], parent2Args[1:]...)
  1577. c.Assert(err, check.IsNil)
  1578. err = d.Stop()
  1579. c.Assert(err, check.IsNil)
  1580. // clear the log file -- we don't need any of it but may for the next part
  1581. // can ignore the error here, this is just a cleanup
  1582. os.Truncate(d.LogfileName(), 0)
  1583. err = d.Start()
  1584. c.Assert(err, check.IsNil)
  1585. for _, num := range []string{"1", "2"} {
  1586. out, err := d.Cmd("inspect", "-f", "{{ .State.Running }}", "parent"+num)
  1587. c.Assert(err, check.IsNil)
  1588. if strings.TrimSpace(out) != "true" {
  1589. log, _ := ioutil.ReadFile(d.LogfileName())
  1590. c.Fatalf("parent container is not running\n%s", string(log))
  1591. }
  1592. }
  1593. }
  1594. func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) {
  1595. testRequires(c, DaemonIsLinux)
  1596. cgroupParent := "test"
  1597. name := "cgroup-test"
  1598. err := s.d.StartWithBusybox("--cgroup-parent", cgroupParent)
  1599. c.Assert(err, check.IsNil)
  1600. defer s.d.Restart()
  1601. out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup")
  1602. c.Assert(err, checker.IsNil)
  1603. cgroupPaths := parseCgroupPaths(string(out))
  1604. c.Assert(len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out)))
  1605. out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name)
  1606. c.Assert(err, checker.IsNil)
  1607. id := strings.TrimSpace(string(out))
  1608. expectedCgroup := path.Join(cgroupParent, id)
  1609. found := false
  1610. for _, path := range cgroupPaths {
  1611. if strings.HasSuffix(path, expectedCgroup) {
  1612. found = true
  1613. break
  1614. }
  1615. }
  1616. c.Assert(found, checker.True, check.Commentf("Cgroup path for container (%s) doesn't found in cgroups file: %s", expectedCgroup, cgroupPaths))
  1617. }
  1618. func (s *DockerDaemonSuite) TestDaemonRestartWithLinks(c *check.C) {
  1619. testRequires(c, DaemonIsLinux) // Windows does not support links
  1620. err := s.d.StartWithBusybox()
  1621. c.Assert(err, check.IsNil)
  1622. out, err := s.d.Cmd("run", "-d", "--name=test", "busybox", "top")
  1623. c.Assert(err, check.IsNil, check.Commentf(out))
  1624. out, err = s.d.Cmd("run", "--name=test2", "--link", "test:abc", "busybox", "sh", "-c", "ping -c 1 -w 1 abc")
  1625. c.Assert(err, check.IsNil, check.Commentf(out))
  1626. c.Assert(s.d.Restart(), check.IsNil)
  1627. // should fail since test is not running yet
  1628. out, err = s.d.Cmd("start", "test2")
  1629. c.Assert(err, check.NotNil, check.Commentf(out))
  1630. out, err = s.d.Cmd("start", "test")
  1631. c.Assert(err, check.IsNil, check.Commentf(out))
  1632. out, err = s.d.Cmd("start", "-a", "test2")
  1633. c.Assert(err, check.IsNil, check.Commentf(out))
  1634. c.Assert(strings.Contains(out, "1 packets transmitted, 1 packets received"), check.Equals, true, check.Commentf(out))
  1635. }
  1636. func (s *DockerDaemonSuite) TestDaemonRestartWithNames(c *check.C) {
  1637. testRequires(c, DaemonIsLinux) // Windows does not support links
  1638. err := s.d.StartWithBusybox()
  1639. c.Assert(err, check.IsNil)
  1640. out, err := s.d.Cmd("create", "--name=test", "busybox")
  1641. c.Assert(err, check.IsNil, check.Commentf(out))
  1642. out, err = s.d.Cmd("run", "-d", "--name=test2", "busybox", "top")
  1643. c.Assert(err, check.IsNil, check.Commentf(out))
  1644. test2ID := strings.TrimSpace(out)
  1645. out, err = s.d.Cmd("run", "-d", "--name=test3", "--link", "test2:abc", "busybox", "top")
  1646. test3ID := strings.TrimSpace(out)
  1647. c.Assert(s.d.Restart(), check.IsNil)
  1648. out, err = s.d.Cmd("create", "--name=test", "busybox")
  1649. c.Assert(err, check.NotNil, check.Commentf("expected error trying to create container with duplicate name"))
  1650. // this one is no longer needed, removing simplifies the remainder of the test
  1651. out, err = s.d.Cmd("rm", "-f", "test")
  1652. c.Assert(err, check.IsNil, check.Commentf(out))
  1653. out, err = s.d.Cmd("ps", "-a", "--no-trunc")
  1654. c.Assert(err, check.IsNil, check.Commentf(out))
  1655. lines := strings.Split(strings.TrimSpace(out), "\n")[1:]
  1656. test2validated := false
  1657. test3validated := false
  1658. for _, line := range lines {
  1659. fields := strings.Fields(line)
  1660. names := fields[len(fields)-1]
  1661. switch fields[0] {
  1662. case test2ID:
  1663. c.Assert(names, check.Equals, "test2,test3/abc")
  1664. test2validated = true
  1665. case test3ID:
  1666. c.Assert(names, check.Equals, "test3")
  1667. test3validated = true
  1668. }
  1669. }
  1670. c.Assert(test2validated, check.Equals, true)
  1671. c.Assert(test3validated, check.Equals, true)
  1672. }
  1673. // TestRunLinksChanged checks that creating a new container with the same name does not update links
  1674. // this ensures that the old, pre gh#16032 functionality continues on
  1675. func (s *DockerDaemonSuite) TestRunLinksChanged(c *check.C) {
  1676. testRequires(c, DaemonIsLinux) // Windows does not support links
  1677. err := s.d.StartWithBusybox()
  1678. c.Assert(err, check.IsNil)
  1679. out, err := s.d.Cmd("run", "-d", "--name=test", "busybox", "top")
  1680. c.Assert(err, check.IsNil, check.Commentf(out))
  1681. out, err = s.d.Cmd("run", "--name=test2", "--link=test:abc", "busybox", "sh", "-c", "ping -c 1 abc")
  1682. c.Assert(err, check.IsNil, check.Commentf(out))
  1683. c.Assert(out, checker.Contains, "1 packets transmitted, 1 packets received")
  1684. out, err = s.d.Cmd("rm", "-f", "test")
  1685. c.Assert(err, check.IsNil, check.Commentf(out))
  1686. out, err = s.d.Cmd("run", "-d", "--name=test", "busybox", "top")
  1687. c.Assert(err, check.IsNil, check.Commentf(out))
  1688. out, err = s.d.Cmd("start", "-a", "test2")
  1689. c.Assert(err, check.NotNil, check.Commentf(out))
  1690. c.Assert(out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received")
  1691. err = s.d.Restart()
  1692. c.Assert(err, check.IsNil)
  1693. out, err = s.d.Cmd("start", "-a", "test2")
  1694. c.Assert(err, check.NotNil, check.Commentf(out))
  1695. c.Assert(out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received")
  1696. }