Attach to a container
/v1.33
/v1.33
/v1.33
/v1.33
POST
/containers/{id}/attach
Container
stream
or logs
parameter must be true
for this endpoint to do anything.docker attach
command for more details.Hijacking
stdin
, stdout
, and stderr
on the same socket.HTTP/1.1 200 OK
Content-Type: application/vnd.docker.raw-stream
[STREAM]
POST /containers/16253994b7c4/attach?stream=1&stdout=1 HTTP/1.1
Upgrade: tcp
Connection: Upgrade
101 UPGRADED
response, and will similarly follow with the raw stream:HTTP/1.1 101 UPGRADED
Content-Type: application/vnd.docker.raw-stream
Connection: Upgrade
Upgrade: tcp
[STREAM]
Stream format
POST /containers/create
, the stream over the hijacked connected is multiplexed to separate out stdout
and stderr
. The stream consists of a series of frames, each containing a header and a payload.stdout
or stderr
). It also contains the size of the associated frame encoded in the last four bytes (uint32
).
STREAM_TYPE
can be:stdin
(is written on stdout
)stdout
stderr
SIZE1, SIZE2, SIZE3, SIZE4
are the four bytes of the uint32
size encoded as big endian.STREAM_TYPE
.1.
2.
stdout
or stderr
depending on the first byte.3.
4.
5.
Stream format when using a TTY
POST /containers/create
, the stream is not multiplexed. The data exchanged over the hijacked connection is simply the raw data from the process PTY and client's stdin
.Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST '/v1.33/containers//attach'
Response Response Example
200 - Example 1
{}
Request
Path Params
id
string
required
Query Params
detachKeys
string
optional
[a-Z]
or ctrl-<value>
where <value>
is one of: a-z
, @
, ^
, [
, ,
or _
.logs
string
optional
stream
is also enabled, once all the previous output has been returned, it will seamlessly transition into streaming current output.stream
string
optional
stdin
string
optional
stdin
stdout
string
optional
stdout
stderr
string
optional
stderr
Responses
Modified at 2022-09-10 17:56:06