diff options
Diffstat (limited to 'cmd/podman/create.go')
-rw-r--r-- | cmd/podman/create.go | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/cmd/podman/create.go b/cmd/podman/create.go index bb9a31467..ead2f6735 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -62,7 +62,7 @@ type createResourceConfig struct { MemorySwappiness int // memory-swappiness OomScoreAdj int //oom-score-adj PidsLimit int64 // pids-limit - ShmSize string + ShmSize int64 Ulimit []string //ulimit } @@ -154,13 +154,24 @@ func createCmd(c *cli.Context) error { return err } + if c.String("cidfile") != "" { + if err := libpod.WriteFile("", c.String("cidfile")); err != nil { + return errors.Wrapf(err, "unable to write cidfile %s", c.String("cidfile")) + } + } + + if len(c.Args()) < 1 { + return errors.Errorf("image name or ID is required") + } + runtime, err := getRuntime(c) if err != nil { return errors.Wrapf(err, "error creating libpod runtime") } defer runtime.Shutdown(false) - createConfig, err := parseCreateOpts(c, runtime) + imageName, _, data, err := imageData(c, runtime, c.Args()[0]) + createConfig, err := parseCreateOpts(c, runtime, imageName, data) if err != nil { return err } @@ -179,6 +190,7 @@ func createCmd(c *cli.Context) error { options = append(options, libpod.WithLabels(createConfig.Labels)) options = append(options, libpod.WithUser(createConfig.User)) options = append(options, libpod.WithShmDir(createConfig.ShmDir)) + options = append(options, libpod.WithShmSize(createConfig.Resources.ShmSize)) ctr, err := runtime.NewContainer(runtimeSpec, options...) if err != nil { return err @@ -195,11 +207,12 @@ func createCmd(c *cli.Context) error { logrus.Debug("new container created ", ctr.ID()) if c.String("cidfile") != "" { - libpod.WriteFile(ctr.ID(), c.String("cidfile")) - } else { - fmt.Printf("%s\n", ctr.ID()) + err := libpod.WriteFile(ctr.ID(), c.String("cidfile")) + if err != nil { + logrus.Error(err) + } } - + fmt.Printf("%s\n", ctr.ID()) return nil } @@ -357,15 +370,13 @@ func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, s // Parses CLI options related to container creation into a config which can be // parsed into an OCI runtime spec -func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, error) { +func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string, data *libpod.ImageData) (*createConfig, error) { + //imageName, imageID, data, err := imageData(c, runtime, image) var command []string var memoryLimit, memoryReservation, memorySwap, memoryKernel int64 var blkioWeight uint16 - if len(c.Args()) < 1 { - return nil, errors.Errorf("image name or ID is required") - } - image := c.Args()[0] + imageID := data.ID if len(c.Args()) > 1 { command = c.Args()[1:] @@ -452,10 +463,6 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er } shmDir = ctr.ShmDir() } - imageName, imageID, data, err := imageData(c, runtime, image) - if err != nil { - return nil, err - } // USER user := c.String("user") @@ -524,6 +531,12 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er return nil, err } + // SHM SIze + shmSize, err := units.FromHumanSize(c.String("shm-size")) + if err != nil { + return nil, errors.Wrapf(err, "unable to translate --shm-size") + } + config := &createConfig{ Runtime: runtime, CapAdd: c.StringSlice("cap-add"), @@ -580,7 +593,7 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er DeviceWriteBps: c.StringSlice("device-write-bps"), DeviceWriteIOps: c.StringSlice("device-write-iops"), DisableOomKiller: c.Bool("oom-kill-disable"), - ShmSize: c.String("shm-size"), + ShmSize: shmSize, Memory: memoryLimit, MemoryReservation: memoryReservation, MemorySwap: memorySwap, |