MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / dockerCreateAndRun

Function dockerCreateAndRun

cli/pkg/docker/run.go:41–125  ·  view source on GitHub ↗

docker run

(cli *client.Client, smartIDEImage, smartIDEName string, hostMapping map[string]string, networks []string, tunnelIP string)

Source from the content-addressed store, hash-verified

39
40// docker run
41func dockerCreateAndRun(cli *client.Client, smartIDEImage, smartIDEName string, hostMapping map[string]string, networks []string, tunnelIP string) { //TODO: Command
42 // 提示文本
43 common.SmartIDELog.Info(i18n.GetInstance().Start.Info_start)
44
45 // check tunnel
46 //isTunnel := common.Contains(args, "-tunnel") //TODO: 不区分大小写
47
48 //get current path
49 currentDir, err := os.Getwd()
50 if err != nil {
51 log.Fatal(err)
52 return
53 }
54
55 // e.g. docker run -i --user root --name=smartide --init -p 3030:3000 --expose 3001 -p 3001:3001 -v "$(pwd):/home/project" registry.cn-hangzhou.aliyuncs.com/smartide/smartide-node:latest --inspect=0.0.0.0:3001
56 // port binding
57 portBinding := nat.PortMap{}
58 portSets := nat.PortSet{}
59 for containerPort, bindingPort := range hostMapping {
60 portBinding[nat.Port(containerPort+"/tcp")] = []nat.PortBinding{{HostIP: "0.0.0.0", HostPort: bindingPort}}
61 portSets[nat.Port(containerPort)] = struct{}{}
62 }
63 if len(tunnelIP) > 0 {
64 portBinding[nat.Port("22/tcp")] = []nat.PortBinding{{HostIP: "0.0.0.0", HostPort: "6022"}}
65 }
66
67 // docker host config
68 hostCfg := &container.HostConfig{
69 Mounts: []mount.Mount{
70 {
71 Type: mount.TypeBind,
72 Source: currentDir,
73 Target: "/home/project",
74 }},
75 PortBindings: portBinding,
76 RestartPolicy: container.RestartPolicy{
77 Name: "always",
78 },
79
80 // AutoRemove: true,
81 }
82
83 // docker network config
84 networkConfig := &network2.NetworkingConfig{
85 EndpointsConfig: map[string]*network2.EndpointSettings{},
86 }
87 // networkMapping[item] = &network.EndpointSettings{}
88 gatewayConfig := &network2.EndpointSettings{
89 //Gateway: networks[0],
90 Aliases: networks,
91 }
92 networkConfig.EndpointsConfig["bridge"] = gatewayConfig //?? 如何配置多个容器网络
93
94 //
95 ctx := context.Background()
96 /* cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
97 if err != nil {
98 panic(err)

Callers

nothing calls this directly

Calls 3

InfoMethod · 0.80
FatalMethod · 0.80
CopyMethod · 0.80

Tested by

no test coverage detected