container.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package compose
  14. import (
  15. "io"
  16. moby "github.com/docker/docker/api/types"
  17. )
  18. const (
  19. // ContainerCreated created status
  20. ContainerCreated = "created"
  21. // ContainerRestarting restarting status
  22. ContainerRestarting = "restarting"
  23. // ContainerRunning running status
  24. ContainerRunning = "running"
  25. // ContainerRemoving removing status
  26. ContainerRemoving = "removing" //nolint
  27. // ContainerPaused paused status
  28. ContainerPaused = "paused" //nolint
  29. // ContainerExited exited status
  30. ContainerExited = "exited" //nolint
  31. // ContainerDead dead status
  32. ContainerDead = "dead" //nolint
  33. )
  34. var _ io.ReadCloser = ContainerStdout{}
  35. // ContainerStdout implement ReadCloser for moby.HijackedResponse
  36. type ContainerStdout struct {
  37. moby.HijackedResponse
  38. }
  39. // Read implement io.ReadCloser
  40. func (l ContainerStdout) Read(p []byte) (n int, err error) {
  41. return l.Reader.Read(p)
  42. }
  43. // Close implement io.ReadCloser
  44. func (l ContainerStdout) Close() error {
  45. l.HijackedResponse.Close()
  46. return nil
  47. }
  48. var _ io.WriteCloser = ContainerStdin{}
  49. // ContainerStdin implement WriteCloser for moby.HijackedResponse
  50. type ContainerStdin struct {
  51. moby.HijackedResponse
  52. }
  53. // Write implement io.WriteCloser
  54. func (c ContainerStdin) Write(p []byte) (n int, err error) {
  55. return c.Conn.Write(p)
  56. }
  57. // Close implement io.WriteCloser
  58. func (c ContainerStdin) Close() error {
  59. return c.CloseWrite()
  60. }