@@ -124,14 +124,13 @@ func (d *DockerStandardPlugin) HandleRequest(w http.ResponseWriter, r *http.Requ
124
124
}
125
125
}
126
126
// If proxy path is "/" use the container's root.
127
+ targetURL := fmt .Sprintf ("http://0.0.0.0:%s" , state .config .ContainerPort )
127
128
if len (state .config .ProxyPaths ) == 1 && state .config .ProxyPaths [0 ] == "/" {
128
- targetURL := fmt .Sprintf ("http://0.0.0.0:%s" , state .config .ContainerPort )
129
129
d .proxyToContainer (targetURL , w , r )
130
130
return true
131
131
}
132
132
for _ , prefix := range state .config .ProxyPaths {
133
133
if strings .HasPrefix (r .URL .Path , prefix ) {
134
- targetURL := fmt .Sprintf ("http://0.0.0.0:%s" , state .config .ContainerPort )
135
134
if r .URL .RawQuery != "" {
136
135
targetURL += "?" + r .URL .RawQuery
137
136
}
@@ -167,12 +166,17 @@ func (d *DockerStandardPlugin) ensureContainer(domain string) error {
167
166
if state .containerID != "" {
168
167
return nil
169
168
}
170
- existingID , err := GetRunningContainer (state .config .CLICommand , state .config .DockerfilePath , state .config .ImageName )
171
- if err == nil && existingID != "" {
172
- state .containerID = existingID
169
+
170
+ // Generate unique container name using domain and container port.
171
+ containerName := fmt .Sprintf ("goup_%s_%s" , domain , state .config .ContainerPort )
172
+
173
+ // Checking if a container with this unique name is already running.
174
+ existingID , err := RunDockerCLI (state .config .CLICommand , state .config .DockerfilePath , "ps" , "--filter" , fmt .Sprintf ("name=%s" , containerName ), "--format" , "{{.ID}}" )
175
+ if err == nil && strings .TrimSpace (existingID ) != "" {
176
+ state .containerID = strings .TrimSpace (existingID )
173
177
return nil
174
178
}
175
- d .DomainLogger .Infof ("[DockerStandardPlugin] Starting container for domain=%s" , domain )
179
+ d .DomainLogger .Infof ("[DockerStandardPlugin] Starting container for domain=%s with tag %s " , domain , containerName )
176
180
cliCmd := state .config .CLICommand
177
181
if cliCmd == "" {
178
182
cliCmd = "docker"
@@ -207,7 +211,7 @@ func (d *DockerStandardPlugin) ensureContainer(domain string) error {
207
211
}
208
212
d .PluginLogger .Infof ("Pull output: %s" , pullOutput )
209
213
}
210
- runArgs := []string {"run" , "-d" , "-p" , fmt .Sprintf ("%s:%s" , state .config .ContainerPort , state .config .ContainerPort )}
214
+ runArgs := []string {"run" , "-d" , "--name" , containerName , "- p" , fmt .Sprintf ("%s:%s" , state .config .ContainerPort , state .config .ContainerPort )}
211
215
runArgs = append (runArgs , state .config .RunArgs ... )
212
216
runArgs = append (runArgs , state .config .ImageName )
213
217
d .PluginLogger .Infof ("[DockerStandardPlugin] Running container with command: %s %s" , cliCmd , strings .Join (runArgs , " " ))
0 commit comments