Answers: <p>The command line is order sensitive. This command:</p>
  
  <pre><code>docker run bot --restart-policy always
  </code></pre>
  
  <p>Runs the <code>bot</code> image as a container with the value of <code>CMD</code> set to <code>--restart-policy always</code>. To modify the restart policy of the container being run, you need to pass the option after <code>run</code> and before your image name:</p>
  
  <pre><code>docker run --restart-policy always bot
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-08-30T14:47:17.487Z
Answers: 2019-08-30T14:47:17.487Z
Answers: BMitch
Body: <p>I'm running a container with the following: <code>docker run bot --restart-policy always</code></p>
  
  <p>However, the container is never actually restarted if it exits due to a stack trace, e.g.,:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/jirabot/source/jbot.py", line 32, in &lt;module&gt;
      rtm = slack_client.rtm_read()
    File "/usr/local/lib/python2.7/site-packages/slackclient/client.py", line 235, in rtm_read
      json_data = self.server.websocket_safe_read()
    File "/usr/local/lib/python2.7/site-packages/slackclient/server.py", line 283, in websocket_safe_read
      data += "{0}\n".format(self.websocket.recv())
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 310, in recv
      opcode, data = self.recv_data()
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 327, in recv_data
      opcode, frame = self.recv_data_frame(control_frame)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 358, in recv_data_frame
      self.pong(frame.data)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 301, in pong
      self.send(payload, ABNF.OPCODE_PONG)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 250, in send
      return self.send_frame(frame)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 275, in send_frame
      l = self._send(data)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 445, in _send
      return send(self.sock, data)
    File "/usr/local/lib/python2.7/site-packages/websocket/_socket.py", line 117, in send
      return sock.send(data)
    File "/usr/local/lib/python2.7/ssl.py", line 707, in send
      v = self._sslobj.write(data)
  socket.error: [Errno 32] Broken pipe
  </code></pre>
  
  <p>What am I missing about the purpose of the restart policy <code>always</code>?</p>
  
Tags: <docker>
Title: Why does docker not restart on a stack trace?
UserDisplayName: MrDuk
ThreadText: # Why does docker not restart on a stack trace?
  
  (Asked by: username_0 on 2019-08-30)
  
  I'm running a container with the following: `docker run bot --restart-policy always`
  
  However, the container is never actually restarted if it exits due to a stack trace, e.g.,:
  
  ```
  Traceback (most recent call last):
    File "/jirabot/source/jbot.py", line 32, in <module>
      rtm = slack_client.rtm_read()
    File "/usr/local/lib/python2.7/site-packages/slackclient/client.py", line 235, in rtm_read
      json_data = self.server.websocket_safe_read()
    File "/usr/local/lib/python2.7/site-packages/slackclient/server.py", line 283, in websocket_safe_read
      data += "{0}\n".format(self.websocket.recv())
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 310, in recv
      opcode, data = self.recv_data()
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 327, in recv_data
      opcode, frame = self.recv_data_frame(control_frame)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 358, in recv_data_frame
      self.pong(frame.data)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 301, in pong
      self.send(payload, ABNF.OPCODE_PONG)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 250, in send
      return self.send_frame(frame)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 275, in send_frame
      l = self._send(data)
    File "/usr/local/lib/python2.7/site-packages/websocket/_core.py", line 445, in _send
      return send(self.sock, data)
    File "/usr/local/lib/python2.7/site-packages/websocket/_socket.py", line 117, in send
      return sock.send(data)
    File "/usr/local/lib/python2.7/ssl.py", line 707, in send
      v = self._sslobj.write(data)
  socket.error: [Errno 32] Broken pipe
  
  ```
  
  What am I missing about the purpose of the restart policy `always`?
  
  **Tags:** docker
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-08-30. Score: 4
  
  The command line is order sensitive. This command:
  
  ```
  docker run bot --restart-policy always
  
  ```
  
  Runs the `bot` image as a container with the value of `CMD` set to `--restart-policy always`. To modify the restart policy of the container being run, you need to pass the option after `run` and before your image name:
  
  ```
  docker run --restart-policy always bot
  
  ```
  
  
  ---
  
  