aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/common/create.go
blob: 7e3dc7fb4efdef199a4f5eb309dea5150a654fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
package common

import (
	"fmt"
	"os"

	"github.com/containers/common/pkg/auth"
	"github.com/containers/podman/v2/cmd/podman/registry"
	"github.com/containers/podman/v2/libpod/define"
	"github.com/spf13/pflag"
)

const sizeWithUnitFormat = "(format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))"

var containerConfig = registry.PodmanConfig()

func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
	createFlags := pflag.FlagSet{}
	createFlags.StringSliceVar(
		&cf.Annotation,
		"annotation", []string{},
		"Add annotations to container (key:value)",
	)
	createFlags.StringSliceVarP(
		&cf.Attach,
		"attach", "a", []string{},
		"Attach to STDIN, STDOUT or STDERR",
	)
	createFlags.StringVar(
		&cf.Authfile,
		"authfile", auth.GetDefaultAuthFile(),
		"Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override",
	)
	createFlags.StringVar(
		&cf.BlkIOWeight,
		"blkio-weight", "",
		"Block IO weight (relative weight) accepts a weight value between 10 and 1000.",
	)
	createFlags.StringSliceVar(
		&cf.BlkIOWeightDevice,
		"blkio-weight-device", []string{},
		"Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)",
	)
	createFlags.StringSliceVar(
		&cf.CapAdd,
		"cap-add", []string{},
		"Add capabilities to the container",
	)
	createFlags.StringSliceVar(
		&cf.CapDrop,
		"cap-drop", []string{},
		"Drop capabilities from the container",
	)
	createFlags.String(
		"cgroupns", "",
		"cgroup namespace to use",
	)
	createFlags.StringVar(
		&cf.CGroupsMode,
		"cgroups", containerConfig.Cgroups(),
		`control container cgroup configuration ("enabled"|"disabled"|"no-conmon"|"split")`,
	)
	createFlags.StringVar(
		&cf.CGroupParent,
		"cgroup-parent", "",
		"Optional parent cgroup for the container",
	)
	createFlags.StringVar(
		&cf.CIDFile,
		"cidfile", "",
		"Write the container ID to the file",
	)
	createFlags.StringVar(
		&cf.ConmonPIDFile,
		"conmon-pidfile", "",
		"Path to the file that will receive the PID of conmon",
	)
	createFlags.Uint64Var(
		&cf.CPUPeriod,
		"cpu-period", 0,
		"Limit the CPU CFS (Completely Fair Scheduler) period",
	)
	createFlags.Int64Var(
		&cf.CPUQuota,
		"cpu-quota", 0,
		"Limit the CPU CFS (Completely Fair Scheduler) quota",
	)
	createFlags.Uint64Var(
		&cf.CPURTPeriod,
		"cpu-rt-period", 0,
		"Limit the CPU real-time period in microseconds",
	)
	createFlags.Int64Var(
		&cf.CPURTRuntime,
		"cpu-rt-runtime", 0,
		"Limit the CPU real-time runtime in microseconds",
	)
	createFlags.Uint64Var(
		&cf.CPUShares,
		"cpu-shares", 0,
		"CPU shares (relative weight)",
	)
	createFlags.Float64Var(
		&cf.CPUS,
		"cpus", 0,
		"Number of CPUs. The default is 0.000 which means no limit",
	)
	createFlags.StringVar(
		&cf.CPUSetCPUs,
		"cpuset-cpus", "",
		"CPUs in which to allow execution (0-3, 0,1)",
	)
	createFlags.StringVar(
		&cf.CPUSetMems,
		"cpuset-mems", "",
		"Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.",
	)
	createFlags.BoolVarP(
		&cf.Detach,
		"detach", "d", false,
		"Run container in background and print container ID",
	)
	createFlags.StringVar(
		&cf.DetachKeys,
		"detach-keys", containerConfig.DetachKeys(),
		"Override the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-cf`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`",
	)
	createFlags.StringSliceVar(
		&cf.Devices,
		"device", containerConfig.Devices(),
		fmt.Sprintf("Add a host device to the container"),
	)
	createFlags.StringSliceVar(
		&cf.DeviceCGroupRule,
		"device-cgroup-rule", []string{},
		"Add a rule to the cgroup allowed devices list",
	)
	createFlags.StringSliceVar(
		&cf.DeviceReadBPs,
		"device-read-bps", []string{},
		"Limit read rate (bytes per second) from a device (e.g. --device-read-bps=/dev/sda:1mb)",
	)
	createFlags.StringSliceVar(
		&cf.DeviceReadIOPs,
		"device-read-iops", []string{},
		"Limit read rate (IO per second) from a device (e.g. --device-read-iops=/dev/sda:1000)",
	)
	createFlags.StringSliceVar(
		&cf.DeviceWriteBPs,
		"device-write-bps", []string{},
		"Limit write rate (bytes per second) to a device (e.g. --device-write-bps=/dev/sda:1mb)",
	)
	createFlags.StringSliceVar(
		&cf.DeviceWriteIOPs,
		"device-write-iops", []string{},
		"Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000)",
	)
	createFlags.Bool(
		"disable-content-trust", false,
		"This is a Docker specific option and is a NOOP",
	)
	createFlags.String("entrypoint", "",
		"Overwrite the default ENTRYPOINT of the image",
	)
	createFlags.StringArrayP(
		"env", "e", containerConfig.Env(),
		"Set environment variables in container",
	)
	createFlags.BoolVar(
		&cf.EnvHost,
		"env-host", false, "Use all current host environment variables in container",
	)
	createFlags.StringSliceVar(
		&cf.EnvFile,
		"env-file", []string{},
		"Read in a file of environment variables",
	)
	createFlags.StringSliceVar(
		&cf.Expose,
		"expose", []string{},
		"Expose a port or a range of ports",
	)
	createFlags.StringSliceVar(
		&cf.GIDMap,
		"gidmap", []string{},
		"GID map to use for the user namespace",
	)
	createFlags.StringSliceVar(
		&cf.GroupAdd,
		"group-add", []string{},
		"Add additional groups to join",
	)
	createFlags.Bool(
		"help", false, "",
	)
	createFlags.StringVar(
		&cf.HealthCmd,
		"health-cmd", "",
		"set a healthcheck command for the container ('none' disables the existing healthcheck)",
	)
	createFlags.StringVar(
		&cf.HealthInterval,
		"health-interval", DefaultHealthCheckInterval,
		"set an interval for the healthchecks (a value of disable results in no automatic timer setup)",
	)
	createFlags.UintVar(
		&cf.HealthRetries,
		"health-retries", DefaultHealthCheckRetries,
		"the number of retries allowed before a healthcheck is considered to be unhealthy",
	)
	createFlags.StringVar(
		&cf.HealthStartPeriod,
		"health-start-period", DefaultHealthCheckStartPeriod,
		"the initialization time needed for a container to bootstrap",
	)
	createFlags.StringVar(
		&cf.HealthTimeout,
		"health-timeout", DefaultHealthCheckTimeout,
		"the maximum time allowed to complete the healthcheck before an interval is considered failed",
	)
	createFlags.StringVarP(
		&cf.Hostname,
		"hostname", "h", "",
		"Set container hostname",
	)
	createFlags.BoolVar(
		&cf.HTTPProxy,
		"http-proxy", true,
		"Set proxy environment variables in the container based on the host proxy vars",
	)
	createFlags.StringVar(
		&cf.ImageVolume,
		"image-volume", DefaultImageVolume,
		`Tells podman how to handle the builtin image volumes ("bind"|"tmpfs"|"ignore")`,
	)
	createFlags.BoolVar(
		&cf.Init,
		"init", false,
		"Run an init binary inside the container that forwards signals and reaps processes",
	)
	createFlags.StringVar(
		&cf.InitPath,
		"init-path", containerConfig.InitPath(),
		// Do not use  the Value field for setting the default value to determine user input (i.e., non-empty string)
		fmt.Sprintf("Path to the container-init binary"),
	)
	createFlags.BoolVarP(
		&cf.Interactive,
		"interactive", "i", false,
		"Keep STDIN open even if not attached",
	)
	createFlags.String(
		"ipc", "",
		"IPC namespace to use",
	)
	createFlags.StringVar(
		&cf.KernelMemory,
		"kernel-memory", "",
		"Kernel memory limit "+sizeWithUnitFormat,
	)
	createFlags.StringArrayVarP(
		&cf.Label,
		"label", "l", []string{},
		"Set metadata on container",
	)
	createFlags.StringSliceVar(
		&cf.LabelFile,
		"label-file", []string{},
		"Read in a line delimited file of labels",
	)
	createFlags.StringVar(
		&cf.LogDriver,
		"log-driver", "",
		"Logging driver for the container",
	)
	createFlags.StringSliceVar(
		&cf.LogOptions,
		"log-opt", []string{},
		"Logging driver options",
	)
	createFlags.StringVarP(
		&cf.Memory,
		"memory", "m", "",
		"Memory limit "+sizeWithUnitFormat,
	)
	createFlags.StringVar(
		&cf.MemoryReservation,
		"memory-reservation", "",
		"Memory soft limit "+sizeWithUnitFormat,
	)
	createFlags.StringVar(
		&cf.MemorySwap,
		"memory-swap", "",
		"Swap limit equal to memory plus swap: '-1' to enable unlimited swap",
	)
	createFlags.Int64Var(
		&cf.MemorySwappiness,
		"memory-swappiness", -1,
		"Tune container memory swappiness (0 to 100, or -1 for system default)",
	)
	createFlags.StringVar(
		&cf.Name,
		"name", "",
		"Assign a name to the container",
	)
	createFlags.BoolVar(
		&cf.NoHealthCheck,
		"no-healthcheck", false,
		"Disable healthchecks on container",
	)
	createFlags.BoolVar(
		&cf.OOMKillDisable,
		"oom-kill-disable", false,
		"Disable OOM Killer",
	)
	createFlags.IntVar(
		&cf.OOMScoreAdj,
		"oom-score-adj", 0,
		"Tune the host's OOM preferences (-1000 to 1000)",
	)
	createFlags.StringVar(
		&cf.OverrideArch,
		"override-arch", "",
		"use `ARCH` instead of the architecture of the machine for choosing images",
	)
	createFlags.StringVar(
		&cf.OverrideOS,
		"override-os", "",
		"use `OS` instead of the running OS for choosing images",
	)
	createFlags.StringVar(
		&cf.OverrideVariant,
		"override-variant", "",
		"Use _VARIANT_ instead of the running architecture variant for choosing images",
	)
	createFlags.String(
		"pid", "",
		"PID namespace to use",
	)
	createFlags.Int64(
		"pids-limit", containerConfig.PidsLimit(),
		"Tune container pids limit (set 0 for unlimited, -1 for server defaults)",
	)
	createFlags.StringVar(
		&cf.Pod,
		"pod", "",
		"Run container in an existing pod",
	)
	createFlags.StringVar(
		&cf.PodIDFile,
		"pod-id-file", "",
		"Read the pod ID from the file",
	)
	createFlags.BoolVar(
		&cf.Privileged,
		"privileged", false,
		"Give extended privileges to container",
	)
	createFlags.BoolVarP(
		&cf.PublishAll,
		"publish-all", "P", false,
		"Publish all exposed ports to random ports on the host interface",
	)
	createFlags.StringVar(
		&cf.Pull,
		"pull", "missing",
		`Pull image before creating ("always"|"missing"|"never")`,
	)
	createFlags.BoolVarP(
		&cf.Quiet,
		"quiet", "q", false,
		"Suppress output information when pulling images",
	)
	createFlags.BoolVar(
		&cf.ReadOnly,
		"read-only", false,
		"Make containers root filesystem read-only",
	)
	createFlags.BoolVar(
		&cf.ReadOnlyTmpFS,
		"read-only-tmpfs", true,
		"When running containers in read-only mode mount a read-write tmpfs on /run, /tmp and /var/tmp",
	)
	createFlags.BoolVar(
		&cf.Replace,
		"replace", false,
		`If a container with the same name exists, replace it`,
	)
	createFlags.StringVar(
		&cf.Restart,
		"restart", "",
		`Restart policy to apply when a container exits ("always"|"no"|"on-failure")`,
	)
	createFlags.BoolVar(
		&cf.Rm,
		"rm", false,
		"Remove container (and pod if created) after exit",
	)
	createFlags.BoolVar(
		&cf.RootFS,
		"rootfs", false,
		"The first argument is not an image but the rootfs to the exploded container",
	)
	createFlags.StringVar(
		&cf.SdNotifyMode,
		"sdnotify", define.SdNotifyModeContainer,
		`control sd-notify behavior ("container"|"conmon"|"ignore")`,
	)
	createFlags.StringArrayVar(
		&cf.SecurityOpt,
		"security-opt", []string{},
		"Security Options",
	)
	createFlags.String(
		"shm-size", containerConfig.ShmSize(),
		"Size of /dev/shm "+sizeWithUnitFormat,
	)
	createFlags.StringVar(
		&cf.SignaturePolicy,
		"signature-policy", "",
		"`Pathname` of signature policy file (not usually used)",
	)
	createFlags.StringVar(
		&cf.StopSignal,
		"stop-signal", "",
		"Signal to stop a container. Default is SIGTERM",
	)
	createFlags.UintVar(
		&cf.StopTimeout,
		"stop-timeout", containerConfig.Engine.StopTimeout,
		"Timeout (in seconds) to stop a container. Default is 10",
	)
	createFlags.StringSliceVar(
		&cf.StoreageOpt,
		"storage-opt", []string{},
		"Storage driver options per container",
	)
	createFlags.StringVar(
		&cf.SubUIDName,
		"subgidname", "",
		"Name of range listed in /etc/subgid for use in user namespace",
	)
	createFlags.StringVar(
		&cf.SubGIDName,
		"subuidname", "",
		"Name of range listed in /etc/subuid for use in user namespace",
	)

	createFlags.StringSliceVar(
		&cf.Sysctl,
		"sysctl", containerConfig.Sysctls(),
		"Sysctl options",
	)
	createFlags.StringVar(
		&cf.Systemd,
		"systemd", "true",
		`Run container in systemd mode ("true"|"false"|"always")`,
	)
	createFlags.StringArrayVar(
		&cf.TmpFS,
		"tmpfs", []string{},
		"Mount a temporary filesystem (`tmpfs`) into a container",
	)
	createFlags.BoolVarP(
		&cf.TTY,
		"tty", "t", false,
		"Allocate a pseudo-TTY for container",
	)
	createFlags.StringVar(
		&cf.Timezone,
		"tz", containerConfig.TZ(),
		"Set timezone in container",
	)
	createFlags.StringVar(
		&cf.Umask,
		"umask", containerConfig.Umask(),
		"Set umask in container",
	)
	createFlags.StringSliceVar(
		&cf.UIDMap,
		"uidmap", []string{},
		"UID map to use for the user namespace",
	)
	createFlags.StringSliceVar(
		&cf.Ulimit,
		"ulimit", containerConfig.Ulimits(),
		"Ulimit options",
	)
	createFlags.StringVarP(
		&cf.User,
		"user", "u", "",
		"Username or UID (format: <name|uid>[:<group|gid>])",
	)
	createFlags.String(
		"userns", os.Getenv("PODMAN_USERNS"),
		"User namespace to use",
	)
	createFlags.String(
		"uts", "",
		"UTS namespace to use",
	)
	createFlags.StringArrayVar(
		&cf.Mount,
		"mount", []string{},
		"Attach a filesystem mount to the container",
	)
	createFlags.StringArrayVarP(
		&cf.Volume,
		"volume", "v", containerConfig.Volumes(),
		"Bind mount a volume into the container",
	)
	createFlags.StringArrayVar(
		&cf.VolumesFrom,
		"volumes-from", []string{},
		"Mount volumes from the specified container(s)",
	)
	createFlags.StringVarP(
		&cf.Workdir,
		"workdir", "w", "",
		"Working directory inside the container",
	)
	createFlags.StringVar(
		&cf.SeccompPolicy,
		"seccomp-policy", "default",
		"Policy for selecting a seccomp profile (experimental)",
	)
	createFlags.StringSliceVar(
		&cf.CgroupConf,
		"cgroup-conf", []string{},
		"Configure cgroup v2 (key=value)",
	)
	return &createFlags
}