summaryrefslogtreecommitdiff
path: root/cmd/podman/attach.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-03-22 13:32:48 -0500
committerbaude <bbaude@redhat.com>2019-04-10 08:59:28 -0500
commitfbcda7772d9fb7667be3a26fbabea0a7b5ea9a58 (patch)
treebe81fbb0543dd51fa9c532f9ec5127c508a1901f /cmd/podman/attach.go
parent2f2c7660c3a30d4c28c03eeeba8edc39f7864c7a (diff)
downloadpodman-fbcda7772d9fb7667be3a26fbabea0a7b5ea9a58.tar.gz
podman-fbcda7772d9fb7667be3a26fbabea0a7b5ea9a58.tar.bz2
podman-fbcda7772d9fb7667be3a26fbabea0a7b5ea9a58.zip
Add the ability to attach remotely to a container
Also, you can now podman-remote run -it. There are some bugs that need to be ironed out but I would prefer to merge this so we can make both progress on start and exec as well as the bugs. * when doing podman-remote run -it foo /bin/bash, you have to press enter to get the prompt to display. with the localized podman, we had to teach it connect to the console first and then start the container so we did not miss anything. * when executing "exit" in the console, we get a hard lockup likely because nobody knows what to do. * custom detach keys are not supported * podman-remote run -it alpine ls does not currently work. only dropping to a shell works. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/attach.go')
-rw-r--r--cmd/podman/attach.go48
1 files changed, 8 insertions, 40 deletions
diff --git a/cmd/podman/attach.go b/cmd/podman/attach.go
index f326f53c3..2fa05a3b1 100644
--- a/cmd/podman/attach.go
+++ b/cmd/podman/attach.go
@@ -1,11 +1,7 @@
package main
import (
- "os"
-
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
- "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -39,49 +35,21 @@ func init() {
flags.BoolVar(&attachCommand.SigProxy, "sig-proxy", true, "Proxy received signals to the process")
flags.BoolVarP(&attachCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
markFlagHiddenForRemoteClient("latest", flags)
+ // TODO allow for passing of a new deatch keys
+ markFlagHiddenForRemoteClient("detach-keys", flags)
}
func attachCmd(c *cliconfig.AttachValues) error {
- args := c.InputArgs
- var ctr *libpod.Container
-
if len(c.InputArgs) > 1 || (len(c.InputArgs) == 0 && !c.Latest) {
return errors.Errorf("attach requires the name or id of one running container or the latest flag")
}
-
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
- if err != nil {
- return errors.Wrapf(err, "error creating libpod runtime")
- }
- defer runtime.Shutdown(false)
-
- if c.Latest {
- ctr, err = runtime.GetLatestContainer()
- } else {
- ctr, err = runtime.LookupContainer(args[0])
- }
-
- if err != nil {
- return errors.Wrapf(err, "unable to exec into %s", args[0])
+ if remoteclient && len(c.InputArgs) != 1 {
+ return errors.Errorf("attach requires the name or id of one running container")
}
-
- conState, err := ctr.State()
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
- return errors.Wrapf(err, "unable to determine state of %s", args[0])
- }
- if conState != libpod.ContainerStateRunning {
- return errors.Errorf("you can only attach to running containers")
- }
-
- inputStream := os.Stdin
- if c.NoStdin {
- inputStream = nil
+ return errors.Wrapf(err, "error creating runtime")
}
-
- // If the container is in a pod, also set to recursively start dependencies
- if err := adapter.StartAttachCtr(getContext(), ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, c.SigProxy, false, ctr.PodID() != ""); err != nil && errors.Cause(err) != libpod.ErrDetach {
- return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
- }
-
- return nil
+ defer runtime.Shutdown(false)
+ return runtime.Attach(getContext(), c)
}