1

anyone can explain to me how to use : ContainerExecLibpod

According to document the api has :

  • AttachStderr
  • AttachStdin
  • AttachStdout

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 ?

1 Answer 1

0

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)

  • First create new exec instance :
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
  • Now create socket connection :
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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.