<p>I run Jenkins and my app is dockerized, i.e. when I run the container it exposes port 3000 and I can point my browser there. On every Github PR I would like to deploy that git commit to a running container somewhere and have Jenkins post back to the PR the link where it can be accessed. On any PR updates it gets auto re-deployed and on PR close/resolve it gets torn down. </p>

<p>I have looked at kubernetes and a little rancher, but what's the easiest way to get this going assuming I can only deploy to one box?</p>

<p>There is a jenkins plugin <a href="https://plugins.jenkins.io/github-pullrequest" rel="nofollow noreferrer">github-pullrequest</a> can resolve your problem.</p>

<p><strong>Prerequisites:</strong></p>

<ol>
<li>You have a jenkins server can access by internet if you want trigger your build by a webhook.</li>
<li>Your have a github API token to access/admin your git repository, it can be generate by yourself in <a href="https://github.com/settings/tokens" rel="nofollow noreferrer">settings</a>.</li>
</ol>

<p>Please follow the guide <a href="https://github.com/KostyaSha/github-integration-plugin/blob/master/docs/Configuration.adoc" rel="nofollow noreferrer">configuration</a> to setup your jenkins integration with github.</p>

<p>After configuration:</p>

<ul>
<li>you can trigger your build by PR events: <strong>opened</strong>/<strong>commit changed</strong>/<strong>closed</strong>, or <strong>comment with specific pattern</strong>.</li>
<li>you can get a PR status via environment variable <strong>${GITHUB_PR_STATE}</strong>, so you can start or stop a container on specific value.</li>
<li>you can publish a comment to a PR to tell the address of your web service after you started docker container.</li>
</ul>

<p>About expose port of cotainer with multi PR, your can just run container with <code>-p 3000</code>, it will auto expose a port in a range on the docker host, <code>docker port &lt;container&gt;</code> will show the specific port number, so for example:</p>

<ul>
<li><code>container1</code> with address <code>&lt;host&gt;:32667</code> for <code>PR1</code></li>
<li><code>container2</code> with address <code>&lt;host&gt;:35989</code> for <code>PR2</code></li>
</ul>
