inspect_unix.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // +build !windows
  2. package daemon
  3. import (
  4. "github.com/docker/docker/api/types"
  5. "github.com/docker/docker/context"
  6. )
  7. // This sets platform-specific fields
  8. func setPlatformSpecificContainerFields(container *Container, contJSONBase *types.ContainerJSONBase) *types.ContainerJSONBase {
  9. contJSONBase.AppArmorProfile = container.AppArmorProfile
  10. contJSONBase.ResolvConfPath = container.ResolvConfPath
  11. contJSONBase.HostnamePath = container.HostnamePath
  12. contJSONBase.HostsPath = container.HostsPath
  13. return contJSONBase
  14. }
  15. // ContainerInspectPre120 gets containers for pre 1.20 APIs.
  16. func (daemon *Daemon) ContainerInspectPre120(ctx context.Context, name string) (*types.ContainerJSONPre120, error) {
  17. container, err := daemon.Get(ctx, name)
  18. if err != nil {
  19. return nil, err
  20. }
  21. container.Lock()
  22. defer container.Unlock()
  23. base, err := daemon.getInspectData(ctx, container)
  24. if err != nil {
  25. return nil, err
  26. }
  27. volumes := make(map[string]string)
  28. volumesRW := make(map[string]bool)
  29. for _, m := range container.MountPoints {
  30. volumes[m.Destination] = m.Path()
  31. volumesRW[m.Destination] = m.RW
  32. }
  33. config := &types.ContainerConfigPre120{
  34. container.Config,
  35. container.hostConfig.VolumeDriver,
  36. container.hostConfig.Memory,
  37. container.hostConfig.MemorySwap,
  38. container.hostConfig.CPUShares,
  39. container.hostConfig.CpusetCpus,
  40. }
  41. return &types.ContainerJSONPre120{base, volumes, volumesRW, config}, nil
  42. }
  43. func addMountPoints(container *Container) []types.MountPoint {
  44. mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
  45. for _, m := range container.MountPoints {
  46. mountPoints = append(mountPoints, types.MountPoint{
  47. Name: m.Name,
  48. Source: m.Path(),
  49. Destination: m.Destination,
  50. Driver: m.Driver,
  51. Mode: m.Mode,
  52. RW: m.RW,
  53. })
  54. }
  55. return mountPoints
  56. }