最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

linux - Podman service api exec to shell - Stack Overflow

programmeradmin5浏览0评论

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 ?

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 ?

Share Improve this question edited Mar 12 at 2:56 mah454 asked Mar 11 at 13:28 mah454mah454 1,9501 gold badge21 silver badges49 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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
发布评论

评论列表(0)

  1. 暂无评论