@@ -635,6 +635,16 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime
635635 for _ , volume := range create .Volumes {
636636 volumes = append (volumes , fmt .Sprintf ("%s:%s" , volume .Source , volume .Target ))
637637 }
638+ 639+ var extraHosts []interface {}
640+ for _ , host := range create .ExtraHosts {
641+ extraHosts = append (extraHosts , fmt .Sprintf ("%s:%s" , host .Hostname , host .IP ))
642+ }
643+ delete (serviceValue , "extraHosts" )
644+ if len (extraHosts ) > 0 {
645+ serviceValue ["extra_hosts" ] = extraHosts
646+ }
647+ 638648 serviceValue ["volumes" ] = volumes
639649 break
640650 }
@@ -842,6 +852,33 @@ func getDockerComposeVolumes(yml []byte) ([]request.Volume, error) {
842852 return res , nil
843853}
844854
855+ func getDockerComposeExtraHosts (yml []byte ) ([]request.ExtraHost , error ) {
856+ var (
857+ composeProject docker.ComposeProject
858+ err error
859+ )
860+ err = yaml .Unmarshal (yml , & composeProject )
861+ if err != nil {
862+ return nil , err
863+ }
864+ var res []request.ExtraHost
865+ for _ , service := range composeProject .Services {
866+ for _ , extraHosts := range service .ExtraHosts {
867+ envArray := strings .Split (extraHosts , ":" )
868+ source := envArray [0 ]
869+ target := ""
870+ if len (envArray ) > 1 {
871+ target = envArray [1 ]
872+ }
873+ res = append (res , request.ExtraHost {
874+ Hostname : source ,
875+ IP : target ,
876+ })
877+ }
878+ }
879+ return res , nil
880+ }
881+ 845882func checkRuntimePortExist (port int , scanPort bool , runtimeID uint ) error {
846883 errMap := make (map [string ]interface {})
847884 errMap ["port" ] = port
@@ -982,6 +1019,11 @@ func handleRuntimeDTO(res *response.RuntimeDTO, runtime model.Runtime) error {
9821019 return err
9831020 }
9841021
1022+ res .ExtraHosts , err = getDockerComposeExtraHosts (composeByte )
1023+ if err != nil {
1024+ return err
1025+ }
1026+ 9851027 defaultVolumes := make (map [string ]string )
9861028 switch runtime .Type {
9871029 case constant .RuntimeNode , constant .RuntimeJava , constant .RuntimePython , constant .RuntimeDotNet :
0 commit comments