|
@@ -1311,6 +1311,18 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+ var containerIDFile *os.File
|
|
|
+ if len(hostConfig.ContainerIDFile) > 0 {
|
|
|
+ if _, err := ioutil.ReadFile(hostConfig.ContainerIDFile); err == nil {
|
|
|
+ return fmt.Errorf("cid file found, make sure the other container isn't running or delete %s", hostConfig.ContainerIDFile)
|
|
|
+ }
|
|
|
+ containerIDFile, err = os.Create(hostConfig.ContainerIDFile)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("failed to create the container ID file: %s", err)
|
|
|
+ }
|
|
|
+ defer containerIDFile.Close()
|
|
|
+ }
|
|
|
+
|
|
|
//create the container
|
|
|
body, statusCode, err := cli.call("POST", "/containers/create", config)
|
|
|
//if image not found try to pull it
|
|
@@ -1341,6 +1353,11 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
|
for _, warning := range runResult.Warnings {
|
|
|
fmt.Fprintf(cli.err, "WARNING: %s\n", warning)
|
|
|
}
|
|
|
+ if len(hostConfig.ContainerIDFile) > 0 {
|
|
|
+ if _, err = containerIDFile.WriteString(runResult.ID); err != nil {
|
|
|
+ return fmt.Errorf("failed to write the container ID to the file: %s", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//start the container
|
|
|
if _, _, err = cli.call("POST", "/containers/"+runResult.ID+"/start", hostConfig); err != nil {
|