title: How to SSH into running docker container from jenkins execute shell
body: <p>I am running a docker container (<code>dind</code>) from jenkins execute shell </p>
  
  <p><code>CONTAINER_ID="$(sudo docker run --privileged -i -d jpetazzo/dind)"</code></p>
  
  <p>To execute docker commands inside container I get into container shell</p>
  
  <p><code>sudo docker exec -it --privileged ${CONTAINER_ID} bash</code></p>
  
  <p>and than I am trying to execute these commands inside <code>dind</code> container.</p>
  
  <p><code>sudo docker pull hubuser/hello-world</code></p>
  
  <p><code>sudo docker run hubuser/hello-world</code></p>
  
  <p><code>sudo docker tag imageId hubuser/hello-world:123</code></p>
  
  <p><code>sudo docker login --username=hubuser --password=password</code></p>
  
  <p><code>sudo docker push hubuser/hello-world</code></p>
  
  <p>All of these 7 commands I have written in jenkins execute shell. Below given 5 commands are executing outside <code>dind</code> container, not inside. If I am trying from terminal than it is attaching to the container shell and executing properly. I want to execute them inside container but from jenkins. I also tried adding <code>exec</code> before every command like this:</p>
  
  <p><code>sudo docker exec -it --privileged ${CONTAINER_ID} sudo docker pull hubuser/hello-world</code></p>
  
  <p><code>sudo docker exec -it --privileged ${CONTAINER_ID} sudo docker run hubuser/hello-world</code></p>
  
  <p>and so on. This executes commands inside <code>dind</code> container but all commands executes in parallel, so before pulling and running the <code>hello-world</code> image, it tries to tag it and push it. There it is not finding any <code>hello-world</code> image to tag and it does't do anything.</p>
  
  <p>I want all my below 5 commands to execute serially inside <code>dind</code> container, that too from jenkins execute shell.</p>