github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/create_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 "runtime" 9 "strings" 10 11 . "github.com/hanks177/podman/v4/test/utils" 12 "github.com/containers/storage/pkg/stringid" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gexec" 16 ) 17 18 var _ = Describe("Podman create", func() { 19 var ( 20 tempdir string 21 err error 22 podmanTest *PodmanTestIntegration 23 ) 24 25 BeforeEach(func() { 26 tempdir, err = CreateTempDirInTempDir() 27 Expect(err).To(BeNil()) 28 podmanTest = PodmanTestCreate(tempdir) 29 podmanTest.Setup() 30 }) 31 32 AfterEach(func() { 33 podmanTest.Cleanup() 34 f := CurrentGinkgoTestDescription() 35 processTestResult(f) 36 37 }) 38 39 It("podman create container based on a local image", func() { 40 session := podmanTest.Podman([]string{"create", "--name", "local_image_test", ALPINE, "ls"}) 41 session.WaitWithDefaultTimeout() 42 cid := session.OutputToString() 43 Expect(session).Should(Exit(0)) 44 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 45 46 check := podmanTest.Podman([]string{"inspect", "local_image_test"}) 47 check.WaitWithDefaultTimeout() 48 data := check.InspectContainerToJSON() 49 Expect(data[0].ID).To(ContainSubstring(cid)) 50 }) 51 52 It("podman create container based on a remote image", func() { 53 session := podmanTest.Podman([]string{"create", BB_GLIBC, "ls"}) 54 session.WaitWithDefaultTimeout() 55 Expect(session).Should(Exit(0)) 56 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 57 }) 58 59 It("podman container create container based on a remote image", func() { 60 containerCreate := podmanTest.Podman([]string{"container", "create", BB_GLIBC, "ls"}) 61 containerCreate.WaitWithDefaultTimeout() 62 Expect(containerCreate).Should(Exit(0)) 63 64 lock := GetPortLock("5000") 65 defer lock.Unlock() 66 session := podmanTest.Podman([]string{"run", "-d", "--name", "registry", "-p", "5000:5000", registry, "/entrypoint.sh", "/etc/docker/registry/config.yml"}) 67 session.WaitWithDefaultTimeout() 68 Expect(session).Should(Exit(0)) 69 70 if !WaitContainerReady(podmanTest, "registry", "listening on", 20, 1) { 71 Skip("Cannot start docker registry.") 72 } 73 74 create := podmanTest.Podman([]string{"container", "create", "--tls-verify=false", ALPINE}) 75 create.WaitWithDefaultTimeout() 76 Expect(create).Should(Exit(0)) 77 Expect(podmanTest.NumberOfContainers()).To(Equal(3)) 78 }) 79 80 It("podman create using short options", func() { 81 session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) 82 session.WaitWithDefaultTimeout() 83 Expect(session).Should(Exit(0)) 84 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 85 }) 86 87 It("podman create using existing name", func() { 88 session := podmanTest.Podman([]string{"create", "--name=foo", ALPINE, "ls"}) 89 session.WaitWithDefaultTimeout() 90 Expect(session).Should(Exit(0)) 91 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 92 93 session = podmanTest.Podman([]string{"create", "--name=foo", ALPINE, "ls"}) 94 session.WaitWithDefaultTimeout() 95 Expect(session).Should(Exit(125)) 96 }) 97 98 It("podman create adds annotation", func() { 99 session := podmanTest.Podman([]string{"create", "--annotation", "HELLO=WORLD", "--name", "annotate_test", ALPINE, "ls"}) 100 session.WaitWithDefaultTimeout() 101 Expect(session).Should(Exit(0)) 102 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 103 104 check := podmanTest.Podman([]string{"inspect", "annotate_test"}) 105 check.WaitWithDefaultTimeout() 106 data := check.InspectContainerToJSON() 107 Expect(data[0].Config.Annotations).To(HaveKeyWithValue("HELLO", "WORLD")) 108 }) 109 110 It("podman create --entrypoint command", func() { 111 session := podmanTest.Podman([]string{"create", "--name", "entrypoint_test", "--entrypoint", "/bin/foobar", ALPINE}) 112 session.WaitWithDefaultTimeout() 113 Expect(session).Should(Exit(0)) 114 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 115 116 result := podmanTest.Podman([]string{"inspect", "entrypoint_test", "--format", "{{.Config.Entrypoint}}"}) 117 result.WaitWithDefaultTimeout() 118 Expect(result).Should(Exit(0)) 119 Expect(result.OutputToString()).To(Equal("/bin/foobar")) 120 }) 121 122 It("podman create --entrypoint \"\"", func() { 123 session := podmanTest.Podman([]string{"create", "--entrypoint", "", ALPINE, "ls"}) 124 session.WaitWithDefaultTimeout() 125 Expect(session).Should(Exit(0)) 126 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 127 128 result := podmanTest.Podman([]string{"inspect", session.OutputToString(), "--format", "{{.Config.Entrypoint}}"}) 129 result.WaitWithDefaultTimeout() 130 Expect(result).Should(Exit(0)) 131 Expect(result.OutputToString()).To(Equal("")) 132 }) 133 134 It("podman create --entrypoint json", func() { 135 jsonString := `[ "/bin/foo", "-c"]` 136 session := podmanTest.Podman([]string{"create", "--name", "entrypoint_json", "--entrypoint", jsonString, ALPINE}) 137 session.WaitWithDefaultTimeout() 138 Expect(session).Should(Exit(0)) 139 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 140 141 result := podmanTest.Podman([]string{"inspect", "entrypoint_json", "--format", "{{.Config.Entrypoint}}"}) 142 result.WaitWithDefaultTimeout() 143 Expect(result).Should(Exit(0)) 144 Expect(result.OutputToString()).To(Equal("/bin/foo -c")) 145 }) 146 147 It("podman create --mount flag with multiple mounts", func() { 148 vol1 := filepath.Join(podmanTest.TempDir, "vol-test1") 149 err := os.MkdirAll(vol1, 0755) 150 Expect(err).To(BeNil()) 151 vol2 := filepath.Join(podmanTest.TempDir, "vol-test2") 152 err = os.MkdirAll(vol2, 0755) 153 Expect(err).To(BeNil()) 154 155 session := podmanTest.Podman([]string{"create", "--name", "test", "--mount", "type=bind,src=" + vol1 + ",target=/myvol1,z", "--mount", "type=bind,src=" + vol2 + ",target=/myvol2,z", ALPINE, "touch", "/myvol2/foo.txt"}) 156 session.WaitWithDefaultTimeout() 157 Expect(session).Should(Exit(0)) 158 159 session = podmanTest.Podman([]string{"start", "test"}) 160 session.WaitWithDefaultTimeout() 161 Expect(session).Should(Exit(0)) 162 163 session = podmanTest.Podman([]string{"logs", "test"}) 164 session.WaitWithDefaultTimeout() 165 Expect(session).Should(Exit(0)) 166 Expect(session.OutputToString()).ToNot(ContainSubstring("cannot touch")) 167 }) 168 169 It("podman create with --mount flag", func() { 170 if podmanTest.Host.Arch == "ppc64le" { 171 Skip("skip failing test on ppc64le") 172 } 173 // NOTE: we force the k8s-file log driver to make sure the 174 // tests are passing inside a container. 175 176 mountPath := filepath.Join(podmanTest.TempDir, "secrets") 177 err := os.Mkdir(mountPath, 0755) 178 Expect(err).ToNot(HaveOccurred()) 179 session := podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test", mountPath), ALPINE, "grep", "/create/test", "/proc/self/mountinfo"}) 180 session.WaitWithDefaultTimeout() 181 Expect(session).Should(Exit(0)) 182 session = podmanTest.Podman([]string{"start", "test"}) 183 session.WaitWithDefaultTimeout() 184 Expect(session).Should(Exit(0)) 185 session = podmanTest.Podman([]string{"logs", "test"}) 186 session.WaitWithDefaultTimeout() 187 Expect(session).Should(Exit(0)) 188 Expect(session.OutputToString()).To(ContainSubstring("/create/test rw")) 189 190 session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_ro", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test,ro", mountPath), ALPINE, "grep", "/create/test", "/proc/self/mountinfo"}) 191 session.WaitWithDefaultTimeout() 192 Expect(session).Should(Exit(0)) 193 session = podmanTest.Podman([]string{"start", "test_ro"}) 194 session.WaitWithDefaultTimeout() 195 Expect(session).Should(Exit(0)) 196 session = podmanTest.Podman([]string{"logs", "test_ro"}) 197 session.WaitWithDefaultTimeout() 198 Expect(session).Should(Exit(0)) 199 Expect(session.OutputToString()).To(ContainSubstring("/create/test ro")) 200 201 session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_shared", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test,shared", mountPath), ALPINE, "awk", `$5 == "/create/test" { print $6 " " $7}`, "/proc/self/mountinfo"}) 202 session.WaitWithDefaultTimeout() 203 Expect(session).Should(Exit(0)) 204 session = podmanTest.Podman([]string{"start", "test_shared"}) 205 session.WaitWithDefaultTimeout() 206 Expect(session).Should(Exit(0)) 207 session = podmanTest.Podman([]string{"logs", "test_shared"}) 208 session.WaitWithDefaultTimeout() 209 Expect(session).Should(Exit(0)) 210 Expect(session.OutputToString()).To(ContainSubstring("rw")) 211 Expect(session.OutputToString()).To(ContainSubstring("shared")) 212 213 mountPath = filepath.Join(podmanTest.TempDir, "scratchpad") 214 err = os.Mkdir(mountPath, 0755) 215 Expect(err).ToNot(HaveOccurred()) 216 session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_tmpfs", "--mount", "type=tmpfs,target=/create/test", ALPINE, "grep", "/create/test", "/proc/self/mountinfo"}) 217 session.WaitWithDefaultTimeout() 218 Expect(session).Should(Exit(0)) 219 session = podmanTest.Podman([]string{"start", "test_tmpfs"}) 220 session.WaitWithDefaultTimeout() 221 Expect(session).Should(Exit(0)) 222 session = podmanTest.Podman([]string{"logs", "test_tmpfs"}) 223 session.WaitWithDefaultTimeout() 224 Expect(session).Should(Exit(0)) 225 Expect(session.OutputToString()).To(ContainSubstring("/create/test rw,nosuid,nodev,relatime - tmpfs")) 226 }) 227 228 It("podman create --pod automatically", func() { 229 session := podmanTest.Podman([]string{"create", "--pod", "new:foobar", ALPINE, "ls"}) 230 session.WaitWithDefaultTimeout() 231 Expect(session).Should(Exit(0)) 232 233 check := podmanTest.Podman([]string{"pod", "ps", "--no-trunc"}) 234 check.WaitWithDefaultTimeout() 235 Expect(check.OutputToString()).To(ContainSubstring("foobar")) 236 }) 237 238 It("podman create --pod-id-file", func() { 239 // First, make sure that --pod and --pod-id-file yield an error 240 // if used together. 241 session := podmanTest.Podman([]string{"create", "--pod", "foo", "--pod-id-file", "bar", ALPINE, "ls"}) 242 session.WaitWithDefaultTimeout() 243 Expect(session).Should(Exit(125)) 244 245 tmpDir, err := ioutil.TempDir("", "") 246 Expect(err).To(BeNil()) 247 defer os.RemoveAll(tmpDir) 248 249 podName := "rudolph" 250 ctrName := "prancer" 251 podIDFile := tmpDir + "pod-id-file" 252 253 // Now, let's create a pod with --pod-id-file. 254 session = podmanTest.Podman([]string{"pod", "create", "--pod-id-file", podIDFile, "--name", podName}) 255 session.WaitWithDefaultTimeout() 256 Expect(session).Should(Exit(0)) 257 258 session = podmanTest.Podman([]string{"pod", "inspect", podName}) 259 session.WaitWithDefaultTimeout() 260 Expect(session).Should(Exit(0)) 261 Expect(session.OutputToString()).To(BeValidJSON()) 262 podData := session.InspectPodToJSON() 263 264 // Finally we can create a container with --pod-id-file and do 265 // some checks to make sure it's working as expected. 266 session = podmanTest.Podman([]string{"create", "--pod-id-file", podIDFile, "--name", ctrName, ALPINE, "top"}) 267 session.WaitWithDefaultTimeout() 268 Expect(session).Should(Exit(0)) 269 270 ctrJSON := podmanTest.InspectContainer(ctrName) 271 Expect(podData).To(HaveField("ID", ctrJSON[0].Pod)) // Make sure the container's pod matches the pod's ID 272 }) 273 274 It("podman run entrypoint and cmd test", func() { 275 name := "test101" 276 create := podmanTest.Podman([]string{"create", "--name", name, redis}) 277 create.WaitWithDefaultTimeout() 278 Expect(create).Should(Exit(0)) 279 280 ctrJSON := podmanTest.InspectContainer(name) 281 Expect(ctrJSON).To(HaveLen(1)) 282 Expect(ctrJSON[0].Config.Cmd).To(HaveLen(1)) 283 Expect(ctrJSON[0].Config.Cmd[0]).To(Equal("redis-server")) 284 Expect(ctrJSON[0].Config).To(HaveField("Entrypoint", "docker-entrypoint.sh")) 285 }) 286 287 It("podman create --pull", func() { 288 session := podmanTest.Podman([]string{"create", "--pull", "never", "--name=foo", "testimage:00000000"}) 289 session.WaitWithDefaultTimeout() 290 Expect(session).To(ExitWithError()) 291 292 session = podmanTest.Podman([]string{"create", "--pull", "always", "--name=foo", "testimage:00000000"}) 293 session.WaitWithDefaultTimeout() 294 Expect(session).Should(Exit(0)) 295 }) 296 297 It("podman create using image list by tag", func() { 298 session := podmanTest.Podman([]string{"create", "--pull=always", "--arch=arm64", "--name=foo", ALPINELISTTAG}) 299 session.WaitWithDefaultTimeout() 300 Expect(session).Should(Exit(0)) 301 session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) 302 session.WaitWithDefaultTimeout() 303 Expect(session).Should(Exit(0)) 304 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) 305 session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) 306 session.WaitWithDefaultTimeout() 307 Expect(session).Should(Exit(0)) 308 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINELISTTAG)) 309 }) 310 311 It("podman create using image list by digest", func() { 312 session := podmanTest.Podman([]string{"create", "--pull=always", "--arch=arm64", "--name=foo", ALPINELISTDIGEST}) 313 session.WaitWithDefaultTimeout() 314 Expect(session).Should(Exit(0)) 315 session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) 316 session.WaitWithDefaultTimeout() 317 Expect(session).Should(Exit(0)) 318 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) 319 session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) 320 session.WaitWithDefaultTimeout() 321 Expect(session).Should(Exit(0)) 322 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINELISTDIGEST)) 323 }) 324 325 It("podman create using image list instance by digest", func() { 326 session := podmanTest.Podman([]string{"create", "--pull=always", "--arch=arm64", "--name=foo", ALPINEARM64DIGEST}) 327 session.WaitWithDefaultTimeout() 328 Expect(session).Should(Exit(0)) 329 session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) 330 session.WaitWithDefaultTimeout() 331 Expect(session).Should(Exit(0)) 332 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) 333 session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) 334 session.WaitWithDefaultTimeout() 335 Expect(session).Should(Exit(0)) 336 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64DIGEST)) 337 }) 338 339 It("podman create using cross-arch image list instance by digest", func() { 340 session := podmanTest.Podman([]string{"create", "--pull=always", "--arch=arm64", "--name=foo", ALPINEARM64DIGEST}) 341 session.WaitWithDefaultTimeout() 342 Expect(session).Should(Exit(0)) 343 session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) 344 session.WaitWithDefaultTimeout() 345 Expect(session).Should(Exit(0)) 346 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) 347 session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) 348 session.WaitWithDefaultTimeout() 349 Expect(session).Should(Exit(0)) 350 Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64DIGEST)) 351 }) 352 353 It("podman create --authfile with nonexistent authfile", func() { 354 session := podmanTest.Podman([]string{"create", "--authfile", "/tmp/nonexistent", "--name=foo", ALPINE}) 355 session.WaitWithDefaultTimeout() 356 Expect(session).To(Not(Equal(0))) 357 }) 358 359 It("podman create --signature-policy", func() { 360 session := podmanTest.Podman([]string{"create", "--pull=always", "--signature-policy", "/no/such/file", ALPINE}) 361 session.WaitWithDefaultTimeout() 362 Expect(session).To(ExitWithError()) 363 364 session = podmanTest.Podman([]string{"create", "--pull=always", "--signature-policy", "/etc/containers/policy.json", ALPINE}) 365 session.WaitWithDefaultTimeout() 366 if IsRemote() { 367 Expect(session).To(ExitWithError()) 368 Expect(session.ErrorToString()).To(ContainSubstring("unknown flag")) 369 } else { 370 Expect(session).Should(Exit(0)) 371 } 372 }) 373 374 It("podman create with unset label", func() { 375 // Alpine is assumed to have no labels here, which seems safe 376 ctrName := "testctr" 377 session := podmanTest.Podman([]string{"create", "--label", "TESTKEY1=", "--label", "TESTKEY2", "--name", ctrName, ALPINE, "top"}) 378 session.WaitWithDefaultTimeout() 379 Expect(session).Should(Exit(0)) 380 381 inspect := podmanTest.Podman([]string{"inspect", ctrName}) 382 inspect.WaitWithDefaultTimeout() 383 data := inspect.InspectContainerToJSON() 384 Expect(data).To(HaveLen(1), "len(InspectContainerToJSON)") 385 Expect(data[0].Config.Labels).To(HaveLen(2)) 386 Expect(data[0].Config.Labels).To(HaveKey("TESTKEY1")) 387 Expect(data[0].Config.Labels).To(HaveKey("TESTKEY2")) 388 }) 389 390 It("podman create with set label", func() { 391 // Alpine is assumed to have no labels here, which seems safe 392 ctrName := "testctr" 393 session := podmanTest.Podman([]string{"create", "--label", "TESTKEY1=value1", "--label", "TESTKEY2=bar", "--name", ctrName, ALPINE, "top"}) 394 session.WaitWithDefaultTimeout() 395 Expect(session).Should(Exit(0)) 396 397 inspect := podmanTest.Podman([]string{"inspect", ctrName}) 398 inspect.WaitWithDefaultTimeout() 399 data := inspect.InspectContainerToJSON() 400 Expect(data).To(HaveLen(1)) 401 Expect(data[0].Config.Labels).To(HaveLen(2)) 402 Expect(data[0].Config.Labels).To(HaveKeyWithValue("TESTKEY1", "value1")) 403 Expect(data[0].Config.Labels).To(HaveKeyWithValue("TESTKEY2", "bar")) 404 }) 405 406 It("podman create with --restart=on-failure:5 parses correctly", func() { 407 ctrName := "testctr" 408 session := podmanTest.Podman([]string{"create", "-t", "--restart", "on-failure:5", "--name", ctrName, ALPINE, "/bin/sh"}) 409 session.WaitWithDefaultTimeout() 410 Expect(session).Should(Exit(0)) 411 412 inspect := podmanTest.Podman([]string{"inspect", ctrName}) 413 inspect.WaitWithDefaultTimeout() 414 data := inspect.InspectContainerToJSON() 415 Expect(data).To(HaveLen(1)) 416 Expect(data[0].HostConfig.RestartPolicy).To(HaveField("Name", "on-failure")) 417 Expect(data[0].HostConfig.RestartPolicy).To(HaveField("MaximumRetryCount", uint(5))) 418 }) 419 420 It("podman create with --restart-policy=always:5 fails", func() { 421 session := podmanTest.Podman([]string{"create", "-t", "--restart", "always:5", ALPINE, "/bin/sh"}) 422 session.WaitWithDefaultTimeout() 423 Expect(session).To(ExitWithError()) 424 }) 425 426 It("podman create with --restart-policy unless-stopped", func() { 427 ctrName := "testctr" 428 unlessStopped := "unless-stopped" 429 session := podmanTest.Podman([]string{"create", "-t", "--restart", unlessStopped, "--name", ctrName, ALPINE, "/bin/sh"}) 430 session.WaitWithDefaultTimeout() 431 Expect(session).Should(Exit(0)) 432 433 inspect := podmanTest.Podman([]string{"inspect", ctrName}) 434 inspect.WaitWithDefaultTimeout() 435 data := inspect.InspectContainerToJSON() 436 Expect(data).To(HaveLen(1)) 437 Expect(data[0].HostConfig.RestartPolicy).To(HaveField("Name", unlessStopped)) 438 }) 439 440 It("podman create with -m 1000000 sets swap to 2000000", func() { 441 numMem := 1000000 442 ctrName := "testCtr" 443 session := podmanTest.Podman([]string{"create", "-t", "-m", fmt.Sprintf("%db", numMem), "--name", ctrName, ALPINE, "/bin/sh"}) 444 session.WaitWithDefaultTimeout() 445 Expect(session).Should(Exit(0)) 446 447 inspect := podmanTest.Podman([]string{"inspect", ctrName}) 448 inspect.WaitWithDefaultTimeout() 449 data := inspect.InspectContainerToJSON() 450 Expect(data).To(HaveLen(1)) 451 Expect(data[0].HostConfig).To(HaveField("MemorySwap", int64(2*numMem))) 452 }) 453 454 It("podman create --cpus 5 sets nanocpus", func() { 455 numCpus := 5 456 nanoCPUs := numCpus * 1000000000 457 ctrName := "testCtr" 458 session := podmanTest.Podman([]string{"create", "-t", "--cpus", fmt.Sprintf("%d", numCpus), "--name", ctrName, ALPINE, "/bin/sh"}) 459 session.WaitWithDefaultTimeout() 460 Expect(session).Should(Exit(0)) 461 462 inspect := podmanTest.Podman([]string{"inspect", ctrName}) 463 inspect.WaitWithDefaultTimeout() 464 data := inspect.InspectContainerToJSON() 465 Expect(data).To(HaveLen(1)) 466 Expect(data[0].HostConfig).To(HaveField("NanoCpus", int64(nanoCPUs))) 467 }) 468 469 It("podman create --replace", func() { 470 // Make sure we error out with --name. 471 session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"}) 472 session.WaitWithDefaultTimeout() 473 Expect(session).Should(Exit(125)) 474 475 // Create and replace 5 times in a row the "same" container. 476 ctrName := "testCtr" 477 for i := 0; i < 5; i++ { 478 session = podmanTest.Podman([]string{"create", "--replace", "--name", ctrName, ALPINE, "/bin/sh"}) 479 session.WaitWithDefaultTimeout() 480 Expect(session).Should(Exit(0)) 481 } 482 }) 483 484 It("podman create sets default stop signal 15", func() { 485 ctrName := "testCtr" 486 session := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "/bin/sh"}) 487 session.WaitWithDefaultTimeout() 488 Expect(session).Should(Exit(0)) 489 490 inspect := podmanTest.Podman([]string{"inspect", ctrName}) 491 inspect.WaitWithDefaultTimeout() 492 data := inspect.InspectContainerToJSON() 493 Expect(data).To(HaveLen(1)) 494 Expect(data[0].Config).To(HaveField("StopSignal", uint(15))) 495 }) 496 497 It("podman create --tz", func() { 498 session := podmanTest.Podman([]string{"create", "--tz", "foo", "--name", "bad", ALPINE, "date"}) 499 session.WaitWithDefaultTimeout() 500 Expect(session).To(ExitWithError()) 501 502 session = podmanTest.Podman([]string{"create", "--tz", "America", "--name", "dir", ALPINE, "date"}) 503 session.WaitWithDefaultTimeout() 504 Expect(session).To(ExitWithError()) 505 506 session = podmanTest.Podman([]string{"create", "--tz", "Pacific/Honolulu", "--name", "zone", ALPINE, "date"}) 507 session.WaitWithDefaultTimeout() 508 inspect := podmanTest.Podman([]string{"inspect", "zone"}) 509 inspect.WaitWithDefaultTimeout() 510 data := inspect.InspectContainerToJSON() 511 Expect(data).To(HaveLen(1)) 512 Expect(data[0].Config).To(HaveField("Timezone", "Pacific/Honolulu")) 513 514 session = podmanTest.Podman([]string{"create", "--tz", "local", "--name", "lcl", ALPINE, "date"}) 515 session.WaitWithDefaultTimeout() 516 inspect = podmanTest.Podman([]string{"inspect", "lcl"}) 517 inspect.WaitWithDefaultTimeout() 518 data = inspect.InspectContainerToJSON() 519 Expect(data).To(HaveLen(1)) 520 Expect(data[0].Config).To(HaveField("Timezone", "local")) 521 }) 522 523 It("podman create --umask", func() { 524 if !strings.Contains(podmanTest.OCIRuntime, "crun") { 525 Skip("Test only works on crun") 526 } 527 528 session := podmanTest.Podman([]string{"create", "--name", "default", ALPINE}) 529 session.WaitWithDefaultTimeout() 530 inspect := podmanTest.Podman([]string{"inspect", "default"}) 531 inspect.WaitWithDefaultTimeout() 532 data := inspect.InspectContainerToJSON() 533 Expect(data).To(HaveLen(1)) 534 Expect(data[0].Config).To(HaveField("Umask", "0022")) 535 536 session = podmanTest.Podman([]string{"create", "--umask", "0002", "--name", "umask", ALPINE}) 537 session.WaitWithDefaultTimeout() 538 inspect = podmanTest.Podman([]string{"inspect", "umask"}) 539 inspect.WaitWithDefaultTimeout() 540 data = inspect.InspectContainerToJSON() 541 Expect(data).To(HaveLen(1)) 542 Expect(data[0].Config).To(HaveField("Umask", "0002")) 543 544 session = podmanTest.Podman([]string{"create", "--umask", "0077", "--name", "fedora", fedoraMinimal}) 545 session.WaitWithDefaultTimeout() 546 inspect = podmanTest.Podman([]string{"inspect", "fedora"}) 547 inspect.WaitWithDefaultTimeout() 548 data = inspect.InspectContainerToJSON() 549 Expect(data).To(HaveLen(1)) 550 Expect(data[0].Config).To(HaveField("Umask", "0077")) 551 552 session = podmanTest.Podman([]string{"create", "--umask", "22", "--name", "umask-short", ALPINE}) 553 session.WaitWithDefaultTimeout() 554 inspect = podmanTest.Podman([]string{"inspect", "umask-short"}) 555 inspect.WaitWithDefaultTimeout() 556 data = inspect.InspectContainerToJSON() 557 Expect(data).To(HaveLen(1)) 558 Expect(data[0].Config).To(HaveField("Umask", "0022")) 559 560 session = podmanTest.Podman([]string{"create", "--umask", "9999", "--name", "bad", ALPINE}) 561 session.WaitWithDefaultTimeout() 562 Expect(session).To(ExitWithError()) 563 Expect(session.ErrorToString()).To(ContainSubstring("Invalid umask")) 564 }) 565 566 It("create container in pod with IP should fail", func() { 567 SkipIfRootless("Setting IP not supported in rootless mode without network") 568 name := "createwithstaticip" 569 pod := podmanTest.RunTopContainerInPod("", "new:"+name) 570 pod.WaitWithDefaultTimeout() 571 Expect(pod).Should(Exit(0)) 572 573 session := podmanTest.Podman([]string{"create", "--pod", name, "--ip", "192.168.1.2", ALPINE, "top"}) 574 session.WaitWithDefaultTimeout() 575 Expect(session).Should(ExitWithError()) 576 }) 577 578 It("create container in pod with mac should fail", func() { 579 SkipIfRootless("Setting MAC Address not supported in rootless mode without network") 580 name := "createwithstaticmac" 581 pod := podmanTest.RunTopContainerInPod("", "new:"+name) 582 pod.WaitWithDefaultTimeout() 583 Expect(pod).Should(Exit(0)) 584 585 session := podmanTest.Podman([]string{"create", "--pod", name, "--mac-address", "52:54:00:6d:2f:82", ALPINE, "top"}) 586 session.WaitWithDefaultTimeout() 587 Expect(session).Should(ExitWithError()) 588 }) 589 590 It("create container in pod with network should not fail", func() { 591 name := "createwithnetwork" 592 pod := podmanTest.RunTopContainerInPod("", "new:"+name) 593 pod.WaitWithDefaultTimeout() 594 Expect(pod).Should(Exit(0)) 595 596 netName := "pod" + stringid.GenerateNonCryptoID() 597 session := podmanTest.Podman([]string{"network", "create", netName}) 598 session.WaitWithDefaultTimeout() 599 Expect(session).Should(Exit(0)) 600 defer podmanTest.removeNetwork(netName) 601 602 session = podmanTest.Podman([]string{"create", "--pod", name, "--network", netName, ALPINE, "top"}) 603 session.WaitWithDefaultTimeout() 604 Expect(session).Should(Exit(0)) 605 }) 606 607 It("create container in pod with ports should fail", func() { 608 name := "createwithports" 609 pod := podmanTest.RunTopContainerInPod("", "new:"+name) 610 pod.WaitWithDefaultTimeout() 611 Expect(pod).Should(Exit(0)) 612 613 session := podmanTest.Podman([]string{"create", "--pod", name, "-p", "8086:80", ALPINE, "top"}) 614 session.WaitWithDefaultTimeout() 615 Expect(session).Should(ExitWithError()) 616 }) 617 618 It("create container in pod publish ports should fail", func() { 619 name := "createwithpublishports" 620 pod := podmanTest.RunTopContainerInPod("", "new:"+name) 621 pod.WaitWithDefaultTimeout() 622 Expect(pod).Should(Exit(0)) 623 624 session := podmanTest.Podman([]string{"create", "--pod", name, "-P", ALPINE, "top"}) 625 session.WaitWithDefaultTimeout() 626 Expect(session).Should(ExitWithError()) 627 }) 628 629 It("create use local store image if input image contains a manifest list", func() { 630 session := podmanTest.Podman([]string{"pull", BB}) 631 session.WaitWithDefaultTimeout() 632 Expect(session).Should(Exit(0)) 633 634 session = podmanTest.Podman([]string{"manifest", "create", "mylist"}) 635 session.WaitWithDefaultTimeout() 636 Expect(session).Should(Exit(0)) 637 638 session = podmanTest.Podman([]string{"manifest", "add", "--all", "mylist", BB}) 639 session.WaitWithDefaultTimeout() 640 Expect(session).Should(Exit(0)) 641 642 session = podmanTest.Podman([]string{"create", "mylist"}) 643 session.WaitWithDefaultTimeout() 644 Expect(session).Should(Exit(0)) 645 }) 646 647 It("podman create -d should fail, can not detach create containers", func() { 648 session := podmanTest.Podman([]string{"create", "-d", ALPINE}) 649 session.WaitWithDefaultTimeout() 650 Expect(session).Should(Exit(125)) 651 Expect(session.ErrorToString()).To(ContainSubstring("unknown shorthand flag")) 652 653 session = podmanTest.Podman([]string{"create", "--detach", ALPINE}) 654 session.WaitWithDefaultTimeout() 655 Expect(session).Should(Exit(125)) 656 Expect(session.ErrorToString()).To(ContainSubstring("unknown flag")) 657 658 session = podmanTest.Podman([]string{"create", "--detach-keys", "ctrl-x", ALPINE}) 659 session.WaitWithDefaultTimeout() 660 Expect(session).Should(Exit(125)) 661 Expect(session.ErrorToString()).To(ContainSubstring("unknown flag")) 662 }) 663 664 It("podman create --platform", func() { 665 session := podmanTest.Podman([]string{"create", "--platform=linux/bogus", ALPINE}) 666 session.WaitWithDefaultTimeout() 667 Expect(session).Should(Exit(125)) 668 expectedError := "no image found in manifest list for architecture bogus" 669 Expect(session.ErrorToString()).To(ContainSubstring(expectedError)) 670 671 session = podmanTest.Podman([]string{"create", "--platform=linux/arm64", "--os", "windows", ALPINE}) 672 session.WaitWithDefaultTimeout() 673 Expect(session).Should(Exit(125)) 674 expectedError = "--platform option can not be specified with --arch or --os" 675 Expect(session.ErrorToString()).To(ContainSubstring(expectedError)) 676 677 session = podmanTest.Podman([]string{"create", "-q", "--platform=linux/arm64", ALPINE}) 678 session.WaitWithDefaultTimeout() 679 Expect(session).Should(Exit(0)) 680 681 setup := podmanTest.Podman([]string{"container", "inspect", session.OutputToString()}) 682 setup.WaitWithDefaultTimeout() 683 Expect(setup).Should(Exit(0)) 684 685 data := setup.InspectContainerToJSON() 686 setup = podmanTest.Podman([]string{"image", "inspect", data[0].Image}) 687 setup.WaitWithDefaultTimeout() 688 Expect(setup).Should(Exit(0)) 689 690 idata := setup.InspectImageJSON() // returns []inspect.ImageData 691 Expect(idata).To(HaveLen(1)) 692 Expect(idata[0]).To(HaveField("Os", runtime.GOOS)) 693 Expect(idata[0]).To(HaveField("Architecture", "arm64")) 694 }) 695 696 It("podman create --uid/gidmap --pod conflict test", func() { 697 create := podmanTest.Podman([]string{"create", "--uidmap", "0:1000:1000", "--pod", "new:testing123", ALPINE}) 698 create.WaitWithDefaultTimeout() 699 Expect(create).ShouldNot(Exit(0)) 700 Expect(create.ErrorToString()).To(ContainSubstring("cannot specify a new uid/gid map when entering a pod with an infra container")) 701 702 create = podmanTest.Podman([]string{"create", "--gidmap", "0:1000:1000", "--pod", "new:testing1234", ALPINE}) 703 create.WaitWithDefaultTimeout() 704 Expect(create).ShouldNot(Exit(0)) 705 Expect(create.ErrorToString()).To(ContainSubstring("cannot specify a new uid/gid map when entering a pod with an infra container")) 706 707 }) 708 709 It("podman create --chrootdirs inspection test", func() { 710 session := podmanTest.Podman([]string{"create", "--chrootdirs", "/var/local/qwerty", ALPINE}) 711 session.WaitWithDefaultTimeout() 712 Expect(session).Should(Exit(0)) 713 714 setup := podmanTest.Podman([]string{"container", "inspect", session.OutputToString()}) 715 setup.WaitWithDefaultTimeout() 716 Expect(setup).Should(Exit(0)) 717 718 data := setup.InspectContainerToJSON() 719 Expect(data).To(HaveLen(1)) 720 Expect(data[0].Config.ChrootDirs).To(HaveLen(1)) 721 Expect(data[0].Config.ChrootDirs[0]).To(Equal("/var/local/qwerty")) 722 }) 723 724 It("podman create --chrootdirs functionality test", func() { 725 session := podmanTest.Podman([]string{"create", "-t", "--chrootdirs", "/var/local/qwerty", ALPINE, "/bin/cat"}) 726 session.WaitWithDefaultTimeout() 727 Expect(session).Should(Exit(0)) 728 ctrID := session.OutputToString() 729 730 setup := podmanTest.Podman([]string{"start", ctrID}) 731 setup.WaitWithDefaultTimeout() 732 Expect(setup).Should(Exit(0)) 733 734 setup = podmanTest.Podman([]string{"exec", ctrID, "cmp", "/etc/resolv.conf", "/var/local/qwerty/etc/resolv.conf"}) 735 setup.WaitWithDefaultTimeout() 736 Expect(setup).Should(Exit(0)) 737 }) 738 })