| 990 | } |
| 991 | |
| 992 | func (s *composeService) buildContainerMountOptions(ctx context.Context, p types.Project, service types.ServiceConfig, inherit *container.Summary) ([]mount.Mount, error) { |
| 993 | mounts := map[string]mount.Mount{} |
| 994 | if inherit != nil { |
| 995 | for _, m := range inherit.Mounts { |
| 996 | if m.Type == "tmpfs" { |
| 997 | continue |
| 998 | } |
| 999 | src := m.Source |
| 1000 | if m.Type == "volume" { |
| 1001 | src = m.Name |
| 1002 | } |
| 1003 | |
| 1004 | img, err := s.apiClient().ImageInspect(ctx, api.GetImageNameOrDefault(service, p.Name)) |
| 1005 | if err != nil { |
| 1006 | return nil, err |
| 1007 | } |
| 1008 | |
| 1009 | if img.Config != nil { |
| 1010 | if _, ok := img.Config.Volumes[m.Destination]; ok { |
| 1011 | // inherit previous container's anonymous volume |
| 1012 | mounts[m.Destination] = mount.Mount{ |
| 1013 | Type: m.Type, |
| 1014 | Source: src, |
| 1015 | Target: m.Destination, |
| 1016 | ReadOnly: !m.RW, |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | volumes := []types.ServiceVolumeConfig{} |
| 1021 | for _, v := range service.Volumes { |
| 1022 | if v.Target != m.Destination || v.Source != "" { |
| 1023 | volumes = append(volumes, v) |
| 1024 | continue |
| 1025 | } |
| 1026 | // inherit previous container's anonymous volume |
| 1027 | mounts[m.Destination] = mount.Mount{ |
| 1028 | Type: m.Type, |
| 1029 | Source: src, |
| 1030 | Target: m.Destination, |
| 1031 | ReadOnly: !m.RW, |
| 1032 | } |
| 1033 | } |
| 1034 | service.Volumes = volumes |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | mounts, err := fillBindMounts(p, service, mounts) |
| 1039 | if err != nil { |
| 1040 | return nil, err |
| 1041 | } |
| 1042 | |
| 1043 | values := make([]mount.Mount, 0, len(mounts)) |
| 1044 | for _, v := range mounts { |
| 1045 | values = append(values, v) |
| 1046 | } |
| 1047 | return values, nil |
| 1048 | } |
| 1049 | |