title: Is there any way to run my containers periodically?
body: <p>I'm trying to write a program that from the main &quot;server&quot;, calls for 2 &quot;agents&quot; that each one of them creates containers. Each container should run periodically and every 10 seconds print the time. The <code>create</code> command is taken from the Std.in as <code>&lt;command&gt; &lt;PATH&gt;</code>.</p>
  <p>For example, I pass 4 containers to create, so <code>agent1</code> creates 2, and <code>agent2</code> creates 2.</p>
  <p>My problem is that when I run this program I only see the second container from agent1 when I type <code>docker ps</code> I get only <code>mycontainer2</code>.<br />
  And only after I stop/remove <code>mycontainer2</code>, only then agent2 creates <code>mycontainer4</code>. (<code>mycontainer1</code> and <code>mycontainer3</code> wasn't created at all).<br />
  Probably the way I created them was wrong. Is there any way I can create all of them and let them run separately?</p>
  <p><strong>Main &quot;server&quot;:</strong></p>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;gopkg.in/yaml.v2&quot;
      &quot;io/ioutil&quot;
      &quot;log&quot;
      &quot;bufio&quot;
      &quot;os&quot;
      &quot;bytes&quot;
      &quot;os/exec&quot;
      &quot;strings&quot;
      &quot;strconv&quot;
  )
  
  type conf struct {
      Name string `yaml:&quot;Name&quot;`
      Amount int `yaml:&quot;Amount&quot;`
      Image string `yaml:&quot;Image&quot;`
  }
  
  func (c *conf) getConf() *conf {
      yamlFile, err := ioutil.ReadFile(&quot;conf.yaml&quot;)
      if err != nil {
          log.Printf(&quot;yamlFile.Get err   #%v &quot;, err)
      }
      err = yaml.Unmarshal(yamlFile, c)
      if err != nil {
          log.Fatalf(&quot;Unmarshal: %v&quot;, err)
      }
  
      return c
  }
  
  func isError(err error) bool {
      if err != nil {
          fmt.Println(err.Error())
      }
  
      return (err != nil)
  }
  
  func showEnvStatus() {
      cmd := exec.Command(&quot;echo&quot;, &quot;Hello from ShowEnv&quot;)
      // cmd.Stdin = strings.NewReader(&quot;some input&quot;)
      var out bytes.Buffer
      cmd.Stdout = &amp;out
      err := cmd.Run()
      if err != nil {
          log.Fatal(err)
      }
      fmt.Printf(&quot;The out put is: %q\n&quot;, out.String())
      return 
  }
  
  func createAgents(c conf){
      var workload = c.Amount/2
      var rightBroderAgent1 = strconv.Itoa(workload)
      var leftBorderAgent2 = strconv.Itoa(c.Amount- workload + 1)
  
      //invoke agent1. Args are the range of the containers numbers for names. (0 : workload)
      cmd1 := exec.Command(&quot;./agent&quot;,&quot;1&quot;, rightBroderAgent1, c.Name, c.Image)
  
      var out bytes.Buffer
      cmd1.Stdout = &amp;out
      err1 := cmd1.Run()
      if err1 != nil {
          fmt.Println(err1)
      }
      fmt.Println(&quot;%q\n&quot;,out.String())
  
      //invoke agent2. Args are the range of the containers numbers for names.(workload+1 : Amount)
      cmd2 := exec.Command(&quot;./agent&quot;,leftBorderAgent2, strconv.Itoa(c.Amount),c.Name, c.Image)
      err2 := cmd2.Run()
      if err2 != nil {
          log.Fatal(err2)
      }
  
      return
  }
  
  func parseCommand(text string) ([]string){
      res := strings.Split(text, &quot; &quot;) 
      return res
  }
  
  func main() {
      i := 0
      for i &lt; 1{
          var args []string
          reader := bufio.NewReader(os.Stdin)
          text, _ := reader.ReadString('\n')
          args = parseCommand(text)
          switch args[0] {
          case &quot;create&quot;:
              var c conf
              c.getConf()
              createAgents(c)
          default:
              fmt.Println(&quot;Unknown command, try again&quot;)
          }
      }
  }
  </code></pre>
  <p>############################# Agent file ##################</p>
  <pre class="lang-golang prettyprint-override"><code>func main(){
      // Args[] structure : {FILE, left border, right border, container's name, image}
      left,_ := strconv.Atoi(os.Args[1])
      right,_ := strconv.Atoi(os.Args[2])
  
      for i := left; i &lt;= right; i++ {
          fmt.Println(left, right)
          var name string = os.Args[3] + strconv.Itoa(i+1) 
          cmd1 := exec.Command(&quot;docker&quot;, &quot;run&quot;, &quot;--name&quot;, name, &quot;-it&quot;, &quot;-d&quot;, os.Args[4])
          cmd2 := exec.Command(&quot;docker&quot;, &quot;cp&quot;, &quot;showtime&quot; ,name + &quot;:/showtime&quot;)
          cmd3 := exec.Command(&quot;docker&quot;, &quot;exec&quot; ,name , &quot;./showtime&quot;)
          
          // cmds := []*exec.Cmd{cmd1,cmd2,cmd3}
  
          err1 := cmd1.Run()
          if err1 != nil {
              fmt.Println(err1)
              os.Exit(2)
          }       
          err2 := cmd2.Run()
          if err2 != nil {
              fmt.Println(err2)
              os.Exit(2)
          }   
          err3 := cmd3.Run()
          if err3 != nil {
              fmt.Println(err3)
              os.Exit(2)
          }       
      }
  }
  </code></pre>