title: Use docker run command to pass arguments to CMD in Dockerfile
body: <p>I'm new to Docker and I'm having a hard time to setup the docker container as I want. I have a nodejs app can take two parameters when start. For example, I can use</p>
  
  <p><code>node server.js 0 dev</code> </p>
  
  <p>or</p>
  
  <p><code>node server.js 1 prod</code></p>
  
  <p>to switch between production mode and dev mode and determine if it should turn the cluster on. Now I want to create docker image with arguments to do the similar thing,  the only thing I can do so far is to adjust the Dockerfile to have a line </p>
  
  <p><code>CMD [ "node", "server.js", "0", "dev"]</code> </p>
  
  <p>and </p>
  
  <p><code>docker build -t me/app .</code> to build the docker.</p>
  
  <p>Then <code>docker run -p 9000:9000 -d me/app</code> to run the docker.</p>
  
  <p>But If I want to switch to prod mode, I need to change the Dockerfile CMD to be </p>
  
  <p><code>CMD [ "node", "server.js", "1", "prod"]</code> , </p>
  
  <p>and I need to kill the old one listening on port 9000 and rebuild the image.
  I wish I can have something like </p>
  
  <p><code>docker run -p 9000:9000 environment=dev cluster=0 -d me/app</code> </p>
  
  <p>to create an image and run the nodejs command with "environment" and "cluster" arguments, so I don't need to change the Dockerfile and rebuild the docker any more. How can I accomplish this?</p>