title: Why can't I always kill a docker process with Ctrl-C?
body: <p>I have a script which I want to optionally run within a container. I have observed that if I run an intermediate script it can be killed with <code>Ctrl-C</code>, however if I do not then it can't.<br>
  Here is an example:<br>
  <code>test1.sh</code>:</p>
  
  <pre><code>#!/bin/bash
  
  if [ "${1}" = true ]; then
    while true; do echo "args: $@"; sleep 1; done
  else
    docker run --rm -it $(docker build -f basic-Dockerfile -q .) /test2.sh $@
  fi
  </code></pre>
  
  <p><code>test2.sh</code>:</p>
  
  <pre><code>#!/bin/bash
  
  /test1.sh true $@
  </code></pre>
  
  <p><code>basic-Dockerfile</code>:</p>
  
  <pre><code>FROM alpine:3.7
  
  RUN apk add --no-cache bash
  COPY test1.sh test2.sh /
  ENTRYPOINT ["bash"]
  </code></pre>
  
  <p>Running <code>./test1.sh true foo bar</code> will happily print out <code>true foo bar</code>, and running <code>./test1.sh foo bar</code> will do the same in a container. Sending <code>Ctrl-C</code> will kill the process and delete the container as expected.<br>
  However if I try to remove the need for an extra file by changing <code>/test2.sh $@</code> to <code>/test1.sh true $@</code>:<br>
  <code>test1.sh</code></p>
  
  <pre><code>#!/bin/bash
  
  if [ "${1}" = true ]; then
    while true; do echo "args: $@"; sleep 1; done
  else
    docker run --rm -it $(docker build -f basic-Dockerfile -q .) /test1.sh true $@
  fi
  </code></pre>
  
  <p>then the process can no longer be terminated with <code>Ctrl-C</code>, and instead must be stopped with <code>docker kill</code>.</p>
  
  <p>Why is this happening?</p>
  
  <p>Docker version 18.06.1-ce running on Windows 10 in WSL</p>