attach_api_1.6.rst 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. :title: Attach stream API
  2. :description: API Documentation for the Attach command in Docker
  3. :keywords: API, Docker, Attach, Stream, REST, documentation
  4. =================
  5. Docker Attach stream API
  6. =================
  7. .. contents:: Table of Contents
  8. 1. Brief introduction
  9. =====================
  10. - This is the Attach stream API for Docker
  11. 2. Format
  12. =========
  13. The attach format is a Header and a Payload (frame).
  14. 2.1 Header
  15. ^^^^^^^^^^
  16. The header will contain the information on which stream write
  17. the stream (stdout or stderr).
  18. It also contain the size of the associated frame encoded on the last 4 bytes (uint32).
  19. It is encoded on the first 8 bytes like this:
  20. header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
  21. STREAM_TYPE can be:
  22. - 0: stdin (will be writen on stdout)
  23. - 1: stdout
  24. - 2: stderr
  25. SIZE1, SIZE2, SIZE3, SIZE4 are the 4 bytes of the uint32 size.
  26. 2.1 Payload (frame)
  27. ^^^^^^^^^^^^^^^^^^^
  28. The payload is the raw stream.
  29. 3. Implementation
  30. =================
  31. The simplest way to implement the Attach protocol is the following:
  32. 1) Read 8 bytes
  33. 2) chose stdout or stderr depending on the first byte
  34. 3) Extract the frame size from the last 4 byets
  35. 4) Read the extracted size and output it on the correct output
  36. 5) Goto 1)