title: Docker: how to execute a batch file when container starts and keep the user in cmd / session
body: <p>I'm using Docker on Windows 2016 Server TP4 with a Windows container.</p>
  
  <p><strong>When the container gets started, I want to execute a certain initialization script (init.bat) but also want to keep the user logged into the container session (in cmd).</strong></p>
  
  <p>With this dockerfile:</p>
  
  <pre><code>FROM windowsservercore
  ADD sources /init
  ENTRYPOINT C:/init/init.bat
  </code></pre>
  
  <p>and this init.bat (which is supposed to run inside the container on startup):</p>
  
  <pre><code>mkdir C:\myfolder
  echo init end
  </code></pre>
  
  <p>and this startup call for the container:</p>
  
  <pre><code>docker run -it test/test cmd
  </code></pre>
  
  <p><strong>the init.bat batch file gets executed inside the container, but the user does not stay logged in the container, but the container exits (with exit code 0).</strong></p>
  
  <p>I don't quite understand why it exits. From how I understand the <a href="https://docs.docker.com/engine/reference/run/#cmd-default-command-or-options" rel="noreferrer">docker documentation</a>:</p>
  
  <blockquote>
    <p>If the image also specifies an ENTRYPOINT then the CMD or COMMAND get
    appended as arguments to the ENTRYPOINT.</p>
  </blockquote>
  
  <p>the <code>cmd</code> command should get appended to the entrypoint, which is my init script, but it doesn't.</p>
  
  <p>I also tried this syntax, but it does not make a difference.</p>
  
  <pre><code>ENTRYPOINT ["C:/init/init.bat"]
  </code></pre>
  
  <p>If I remove the ENTRYPOINT from the dockerfile and start the container with the <code>cmd</code> command, I stay in the session and I can of course run the init.bat script manually and it works, but I want it to run automatically.</p>
  
  <p>When I work with Ubuntu containers, I usually use <code>supervisord</code> to execute any initialization scripts, and bin/bash (which equivalents to <code>cmd</code> on Windows) as the command.
  I am not sure how to do the same on a Windows container though.</p>