title: Unexpected behaviour from awk in docker-machine
body: <p>Inspired by <a href="https://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers">this post</a>, I'm attempting to use <code>docker-machine</code> on my Mac to stop a running container. However, <code>awk</code> appears to behave differently in <code>docker-machine ssh</code> than when run directly "in" the container.</p>
  
  <p>When I'm ssh'd to the container directly, everything works as expected:</p>
  
  <pre><code>me@myMac:~$ docker-machine ssh default
  docker@default:~$ docker ps
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
  028fd7148881        myrepo/mycontainer  "apachectl -DFOREGROU"   14 minutes ago      Up 14 minutes       0.0.0.0:80-&gt;80/tcp   gloomy_mayer
  docker@default:~$ docker ps | awk 'NR &gt; 1 {print $1}'
  028fd7148881
  docker@default:~$ docker ps | awk 'NR &gt; 1 {print $1}' | xargs --no-run-if-empty docker kill
  028fd7148881
  docker@default:~$ docker ps
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  </code></pre>
  
  <p>But when run remotely, <code>awk</code> behaves differently:</p>
  
  <pre><code>me@myMac:~$ docker-machine ssh default "docker ps"
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
  7927b10b8a28        myrepo/mycontainer  "apachectl -DFOREGROU"   11 seconds ago      Up 10 seconds       80/tcp              happy_wozniak
  me@myMac:~$ docker-machine ssh default "docker ps | awk 'NR &gt; 1 {print $1}'"
  7927b10b8a28        myrepo/mycontainer  "apachectl -DFOREGROU"   About a minute ago   Up About a minute   80/tcp              happy_wozniak
  me@myMac:~$ docker-machine ssh default "docker ps | awk 'NR &gt; 1 {print $1}' | xargs --no-run-if-empty docker kill"
  7927b10b8a28
  Failed to kill container (myrepo/mycontainer): Error response from daemon: Cannot kill container myrepo/mycontainer: No such container: myRepo/myContainer
  Failed to kill container (apachectl -DFOREGROU): Error response from daemon: Cannot kill container apachectl -DFOREGROU: No such container: apachectl -DFOREGROU
  Failed to kill container (3): Error response from daemon: Cannot kill container 3: No such container: 3
  ...
  </code></pre>
  
  <p>Why does <code>awk</code> behave differently under <code>docker-machine</code>?</p>