linuxcontainerspodman

Podman service api exec to shell


anyone can explain to me how to use : ContainerExecLibpod

According to document the api has :

I want to know how to use that api parameters .
the podman api service started with this command :

> podman system service -t 0 tcp://localhost:9091

I create container :

> podman run -it --name=ubuntu -h ubuntu-container ubuntu:latest /bin/bash   

now i test api with this command :

> curl -X POST 'http://localhost:9091/v5/libpod/containers/ubuntu/exec' -H "Content-Type: application/json" --data '{"AttachStderr": true,"AttachStdin": true,"AttachStdout": true,"Cmd" : ["ls"],"Tty": true}'
{"Id":"154a611f39691c7e76d1aceef28759c701ea0854422d07ff663f4f75faf7af44"}

the curl only result the simple json contain Id , how to use stdIn , stdOut , stdErr ?


Solution

  • finally after two week found the solution.

    Attach To Container

    Create socket connection and send request like this :

    > telnet localhot 9000
    POST /v4.6.0/libpod/containers/busybox/attach?stream=true&stdout=true&stdin=true&stderr=true HTTP/1.1
    Host: 127.0.0.1:9000
    Upgrade: tcp
    Connection: Upgrade
    
    ### Phase 1: PODMAN SERVER RESPONSE ###
    HTTP/1.1 101 UPGRADED
    Content-Type: tcp
    Connection: Upgrade
    Upgrade: application/vnd.docker.raw-stream
    
    ### Phase 2: INTERACTIVE SESSION ###
    / # ls
    bin    etc    lib    proc   run    tmp    var
    dev    home   lib64  root   sys    usr
    

    Exec inside Container (Interactive Mode)

    curl -X POST 'http://localhost:9000/v5/libpod/containers/busybox/exec' -H "Content-Type: application/json" --data '{"AttachStderr": true,"AttachStdin": true,"AttachStdout": true,"Cmd" : ["/bin/sh"],"Tty": true}' -s | jq -r .Id
    
    POST /v5.0.0/libpod/exec/[paste id of exec instance]/start HTTP/1.1
    Host: 127.0.0.1:9000
    Content-Type: application/json
    Content-Length: 46
    
    {"Detach": false, "Tty": true, "h": 0, "w": 0}
    
    ### Phase 1: PODMAN SERVER RESPONSE ### 
    HTTP/1.1 200 OK
    Content-Type: application/vnd.docker.raw-stream
    
    ### Phase 2: INTERACTIVE SESSION ###
    / # ls
    bin    etc    lib    proc   run    tmp    var
    dev    home   lib64  root   sys    usr