Commit Graph

93 Commits

Author SHA1 Message Date
Boaz Shuster 11e5c53d11 Add the rmi flag to podman-run to delete container image
The --rmi flag will delete the container image after its execution
unless that image is already been used by another container(s).

This is useful when one wants to execute a container once and remove
any resources attached to it.

Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
2020-03-03 14:27:11 +02:00
Brent Baude b438cb2cce seperate container create network options
this pr splits off some of the network container create options into a different flag set.  the options in question are:

--add-host
--dns
--dns-opt
--dns-search
--ip
--mac-address
--network
--no-hosts
--publish

in the future, these options are going to be added to the pod create flags.  this makes that transition easier and provides for less code duplication.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-03 15:30:17 -06:00
Daniel J Walsh 45e9a6b12e
Remove c.String(net)
We have a lot of cludgy code trying to make --net and --network equivalent.
This will allow --net to still exists but will eliminate the help and confusion.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-01-16 09:23:32 -05:00
Qi Wang d7c0f968ca fix bug check nonexist authfile
Use GetDefaultAuthFile() from buildah.
For podman command(except login), if authfile does not exist returns error.

close #4328

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-11-05 21:32:18 -05:00
baude 867d49957b Add ability to redirect bash for run -i
Signed-off-by: baude <bbaude@redhat.com>
2019-10-15 08:00:13 -05:00
Hunor Csomortáni 3e53bfe36e Make the healthcheck flags compatible with Docker CLI
Docker CLI calls the healthcheck flags "--health-*", instead of
"--healthcheck-*".

Introduce the former, in order to keep compatibility, and alias
the later, in order to avoid breaking current usage.

Change "--healthcheck-*" to "--health-*" in the docs and tests.

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
2019-07-16 06:15:28 +02:00
baude e053e0e05e first pass of corrections for golangci-lint
Signed-off-by: baude <bbaude@redhat.com>
2019-07-10 15:52:17 -05:00
baude fec1de6ef4 trivial cleanups from golang
the results of a code cleanup performed by the goland IDE.

Signed-off-by: baude <bbaude@redhat.com>
2019-07-03 15:41:33 -05:00
Daniel J Walsh baed81029b
Fixup Flags
Mark hidden all references to signature-policy
Default all uses of --authfile
Add --authfile support to podman run and podman create.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-05-20 13:53:32 -04:00
Giuseppe Scrivano f49e0c19ed
runtime: pass down the context
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-26 22:23:49 +02:00
baude 6fb0a706af Fix segfaults attribute to missing options
In cases where the remote client culls options to a command, we need to
be sure that the lookup for that flag does not result in a nil pointer.
To do so, we add a Remote attribute to the podman struct and then cli
helper funcs are now aware they are remote.

Signed-off-by: baude <bbaude@redhat.com>
2019-04-15 12:21:51 -05:00
baude 495f2ce515 Fixes for podman-remote run and attach
Fixes the ability to run (create,start) a container and attach to its
console correctly.  We can now also exit from the console without
hanging the remote client.

Signed-off-by: baude <bbaude@redhat.com>
2019-04-11 13:51:50 -05:00
baude ba65301c95 podman-remote create|run
add the ability to create and run containers via the podman-remote
client.

we now create an intermediate layer from the the create/run cli flags.
the intermediate layer can be converted into a createconfig or into a
varlink struct.  Once transported, the varlink struct can be converted
back to an intermediate layer and then to a createconfig.

remote terminals are not supported yet.

Signed-off-by: baude <bbaude@redhat.com>
2019-04-08 09:05:31 -05:00
Giuseppe Scrivano ed326206f2
rootless: remove SkipStorageSetup()
in the few places where we care about skipping the storage
initialization, we can simply use the process effective UID, instead
of relying on a global boolean flag.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-01 13:24:04 +02:00
Matthew Heon 5ed62991dc Remove ulele/deepcopier in favor of JSON deep copy
We have a very high performance JSON library that doesn't need to
perform code generation. Let's use it instead of our questionably
performant, reflection-dependent deep copy library.

Most changes because some functions can now return errors.

Also converts cmd/podman to use jsoniter, instead of pkg/json,
for increased performance.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-03-27 20:00:31 -04:00
Ed Santiago 8f82edbcb3 Usage messages: deduplicate '(default true)' et al
Remove hardcoded '(default: true)' strings from bool flags,
and '(default this-or-that)' from string flags.

First because it's unmaintainable duplication that would cause
confusion should someone ever change the default and not notice
the message.

Second, because cobra[1] already prints '(default XXXX)' for
all options with non-false non-nil default. So in each of
these cases, current podman help behavior is:

    $ podman login --help
    ...
       --tls-verify  Require HTTPS ... (default: true) (default true)

This PR eliminates that duplication.

 [1] actually spf13/pflag/flag.go

The only nontrivial one of these is start.go, where the default
for sigProxy depends on the --attach flag. Solution: change
the command-line default to false, and implement the new
conditional default in logic. Bonus: removed unnecessary
check, because now if sigProxy is set without --attach,
we can guarantee that it was done by the user. But please
pay close scrutiny to this particular section in case
there's something I missed.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2019-03-13 16:34:31 -06:00
Giuseppe Scrivano 17b60891b6
rm: fix cleanup race
we fire the cleanup process asynchronously so we might race with a
command like: podman run --rm --name foo ... && podman run --rm --name foo

Fix it by ensuring the container is deleted before we exit.  This
will race with the "cleanup" process, but it is fine as one of the two
commands will fail with ErrNoSuchCtr while the other succeeds.

Closes: https://github.com/containers/libpod/issues/2619

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-13 20:26:56 +01:00
baude 651520389d preparation for remote-client create container
to prepare for being able to remotely run a container, we need to
perform a refactor to get code out of main because it is not
reusable.  the shared location is a good starting spot though
eventually some will likely end up in pkg/spec/ at some point.

Signed-off-by: baude <bbaude@redhat.com>
2019-03-11 09:42:22 -05:00
Daniel J Walsh 9a39c60e46
Fix help commands to show short and long description.
Cleanup lots of help information to look good when displayed.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-03-07 13:46:59 -05:00
Ed Santiago a20ff42134 Better usage synopses for subcommands
Conceptually simple: include, where applicable, a brief
description of command-line options for each subcommand.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2019-02-26 18:10:36 -07:00
Sebastian Jug 7141f97270 OpenTracing support added to start, stop, run, create, pull, and ps
Drop context.Context field from cli.Context

Signed-off-by: Sebastian Jug <sejug@redhat.com>
2019-02-18 09:57:08 -05:00
OpenShift Merge Robot 3f32eae56f
Merge pull request #2357 from TomSweeneyRedHat/dev/tsweeney/cobrahelp3
Add 3rd chunk of Cobra examples
2019-02-17 22:44:04 +01:00
TomSweeneyRedHat b62c0e703d Add 3rd chunk of Cobra examples
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Adds the third chunk of Cobra examples to the cli help.
As were putting together a release tomorrow, tried to
hit the heavy commands with this PR.

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2019-02-17 13:49:05 -05:00
Peter Hunt 81804fc464 pod infra container is started before a container in a pod is run, started, or attached.
Prior, a pod would have to be started immediately when created, leading to confusion about what a pod state should be immediately after creation. The problem was podman run --pod ... would error out if the infra container wasn't started (as it is a dependency). Fix this by allowing for recursive start, where each of the container's dependencies are started prior to the new container. This is only applied to the case where a new container is attached to a pod.

Also rework container_api Start, StartAndAttach, and Init functions, as there was some duplicated code, which made addressing the problem easier to fix.

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-02-15 16:39:24 -05:00
Daniel J Walsh 52df1fa7e0
Fix volume handling in podman
iFix builtin volumes to work with podman volume

Currently builtin volumes are not recored in podman volumes when
they are created automatically. This patch fixes this.

Remove container volumes when requested

Currently the --volume option on podman remove does nothing.
This will implement the changes needed to remove the volumes
if the user requests it.

When removing a volume make sure that no container uses the volume.

Signed-off-by: Daniel J Walsh dwalsh@redhat.com
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-02-14 13:21:52 -05:00
Matthew Heon 28ee842b76 Address review comments on #2319
Signed-off-by: Matthew Heon <mheon@redhat.com>
2019-02-12 13:11:07 -05:00
Matthew Heon 19a03976f7 Retain a copy of container exit file on cleanup
When cleaning up containers, we presently remove the exit file
created by Conmon, to ensure that if we restart the container, we
won't have conflicts when Conmon tries writing a new exit file.

Unfortunately, we need to retain that exit file (at least until
we get a workable events system), so we can read it in cases
where the container has been removed before 'podman run' can read
its exit code.

So instead of removing it, rename it, so there's no conflict with
Conmon, and we can still read it later.

Fixes: #1640

Signed-off-by: Matthew Heon <mheon@redhat.com>
2019-02-12 12:57:11 -05:00
Matthew Heon b6775d5d22 Fix manual detach from containers to not wait for exit
At present, when manually detaching from an attached container
(using the detach hotkeys, default C-p C-q), Podman will still
wait for the container to exit to obtain its exit code (so we can
set Podman's exit code to match). This is correct in the case
where attach finished because the container exited, but very
wrong for the manual detach case.

As a result of this, we can no longer guarantee that the cleanup
and --rm functions will fire at the end of 'podman run' - we may
be exiting before we get that far. Cleanup is easy enough - we
swap to unconditionally using the cleanup processes we've used
for detached and rootless containers all along. To duplicate --rm
we need to also teach 'podman cleanup' to optionally remove
containers instead of cleaning them up.

(There is an argument for just using 'podman rm' instead of
'podman cleanup --rm', but cleanup does have different semantics
given that we only ever expect it to run when the container has
just exited. I think it might be useful to keep the two separate
for things like 'podman events'...)

Signed-off-by: Matthew Heon <mheon@redhat.com>
2019-02-12 10:14:57 -05:00
Daniel J Walsh ccbc4fb006
Don't show global flags except for podman command
Subcommands should not be showing the global flags.  This causes the important
information to scroll off the screen.

Also fixed a typo on runCommmand (Too many 'm's)

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-02-12 05:14:38 -07:00
baude 13d2354bc6 Separate remote and local commands
In the previous CLI, we had an accurate depiction of commands
available for the remote client and those available for the
local client.

Signed-off-by: baude <bbaude@redhat.com>
2019-02-11 12:53:21 -06:00
baude 25a3923b61 Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the
project is more well maintained.  There are also some technical reasons
as well which extend into our remote client work.

Signed-off-by: baude <bbaude@redhat.com>
2019-02-08 10:26:43 -06:00
Daniel J Walsh 0830bb9035
Capatilize all usage and descriptions
We have no consistancy in out option usages and descritions
on whether or not the first letter should be capatalized.

This patch forces them all to be capatilized.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-02-05 10:42:04 -08:00
Daniel J Walsh 74d984e056
Add podman system prune and info commands
We are missing the equivalence of the docker system commands

This patch set adds `podman system prune`
and `podman system info`

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-02-05 10:41:55 -08:00
baude 9786542620 failed containers with --rm should remove themselves
when starting or running a container that has --rm, if the starting
container fails (like due to an invalid command), the container should
get removed.

Resolves: #1985

Signed-off-by: baude <bbaude@redhat.com>
2018-12-12 10:55:53 -06:00
Matthew Heon 562fa57dc9 Move rootless storage config into libpod
Previous commits ensured that we would use database-configured
paths if not explicitly overridden.

However, our runtime generation did unconditionally override
storage config, which made this useless.

Move rootless storage configuration setup to libpod, and change
storage setup so we only override if a setting is explicitly
set, so we can still override what we want.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 15:21:35 -05:00
Šimon Lukašík 59f93edacc --interactive shall keep STDIN attached even when not explicitly called out
Addressing:

    podman run -it -a STDERR --rm alpine /bin/ash

hanging. As we droped stdin as soon as -a was used. Notice this is contrary to
what D-tool does and contrary to what podman help implies:

    podman run --help | grep interact
    --interactive, -i                  Keep STDIN open even if not attached

Signed-off-by: Šimon Lukašík <slukasik@redhat.com>
2018-11-03 19:18:37 +01:00
Qi Wang d73600626d Sort all command flags
Signed-off-by: Qi Wang <qiwan@redhat.com>
2018-10-11 13:17:14 -04:00
Matthew Heon 2c7f97d5a7 Add ContainerStateExited and OCI delete() in cleanup()
To work better with Kata containers, we need to delete() from the
OCI runtime as a part of cleanup, to ensure resources aren't
retained longer than they need to be.

To enable this, we need to add a new state to containers,
ContainerStateExited. Containers transition from
ContainerStateStopped to ContainerStateExited via cleanupRuntime
which is invoked as part of cleanup(). A container in the Exited
state is identical to Stopped, except it has been removed from
the OCI runtime and thus will be handled differently when
initializing the container.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-10-02 12:05:22 -04:00
Matthew Heon 9e81f9daa4 Refactor Wait() to not require a timeout
We added a timeout for convenience, but most invocations don't
care about it. Refactor it into WaitWithTimeout() and add a
Wait() that doesn't require a timeout and uses the default.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1527
Approved by: mheon
2018-09-21 20:07:51 +00:00
Giuseppe Scrivano c4b15ce46b rootless: fix create with images not in the storage
This chunk was mistakenly removed with ecec1a5430

Introduce it back as it solves the pull of an image that is not yet in
the storage when using create/run.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1521
Approved by: baude
2018-09-21 13:04:36 +00:00
Matthew Heon 8b21e2ecf5
Merge pull request #1461 from rhatdan/run
Remove duplicate code between create.go and run.go
2018-09-14 16:56:34 -04:00
Daniel J Walsh ecec1a5430
Remove duplicate code between create.go and run.go
Create two new createInit for checking if the cotnainer is initialized
correctly.
createContainer which creates the actual container and containerConfig

Also added libpodruntime.GetContainerRuntime to put common runtime code
into separate function.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-09-13 12:16:14 -04:00
Daniel J Walsh 9ec82caa31
Add --interval flag to podman wait
Waiting uses a lot of CPU, so drop back to checking once/second
and allow user to pass in the interval.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-09-13 10:11:00 -04:00
Giuseppe Scrivano 807f6f8d8f rootless: check uid with Geteuid() instead of Getuid()
change the tests to use chroot to set a numeric UID/GID.

Go syscall.Credential doesn't change the effective UID/GID of the
process.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1372
Approved by: mheon
2018-09-04 14:36:57 +00:00
Giuseppe Scrivano 8ca67d2794 rootless, run: support --pod
move re-exec later on, so that we can check whether we need to join
the infra container user namespace or we need to create another one.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1372
Approved by: mheon
2018-09-04 14:36:57 +00:00
Valentin Rothberg 3839c00ae2 don't print help message for usage errors
Don't print potentially verbose help messages in case of usage errors,
but print only the usage error followed by a pointer to the command's
help.  This aligns with Docker.

```
$ podman run -h
flag needs an argument: -h
See 'podman run --help'.
```

Signed-off-by: Valentin Rothberg <vrothberg@suse.com>

Closes: #1379
Approved by: rhatdan
2018-08-31 10:19:11 +00:00
Valentin Rothberg 6751b2c350 run/create: reserve `-h` flag for hostname
Move the `-h` short flag from `--help` to `--hostname` for podman-run,
podman-create and podman-pod-create to be compatible with Docker.

Fixes: #1367
Signed-off-by: Valentin Rothberg <vrothberg@suse.com>

Closes: #1373
Approved by: rhatdan
2018-08-30 15:45:13 +00:00
Daniel J Walsh d20f3a5146 switch projectatomic to containers
Need to get some small changes into libpod to pull back into buildah
to complete buildah transition.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1270
Approved by: mheon
2018-08-16 17:12:36 +00:00
Daniel J Walsh f9152d075a Cleanup descriptions and help information
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1167
Approved by: baude
2018-07-27 02:17:29 +00:00
Daniel J Walsh 35b7a875fd Need to wait for container to exit before completing run/start completes
This fixes a race condition where conmon is still writing the exit
file and the container is exiting.

Also we should not be ignoring the -a stdin flag if the user specifies
--interactive mode.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1086
Approved by: baude
2018-07-13 14:14:42 +00:00