title: Dockerized nginx is not starting
body: <p>I have tried following some tutorials and documentation on dockerizing my web server, but I am having trouble getting the service to run via the docker run command.</p>
  
  <p>This is my Dockerfile:</p>
  
  <pre><code>FROM ubuntu:trusty
  
  #Update and install stuff
  RUN apt-get update
  RUN apt-get install -y python-software-properties aptitude screen htop nano nmap nginx
  
  #Add files
  ADD src/main/resources/ /usr/share/nginx/html
  
  EXPOSE 80
  CMD service nginx start
  </code></pre>
  
  <p>I create my image: </p>
  
  <pre><code>docker build -t myImage .
  </code></pre>
  
  <p>And when I run it:</p>
  
  <pre><code>docker run -p 81:80 myImage
  </code></pre>
  
  <p>it seems to just stop:</p>
  
  <pre><code>docker ps -a
  
  CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
  90e54a254efa        pms-gui:latest      /bin/sh -c service n   3 seconds ago       Exit 0                                  prickly_bohr
  </code></pre>
  
  <p>I would expect this to be running with port 81->80 but it is not. Running </p>
  
  <pre><code>docker start 90e
  </code></pre>
  
  <p>does not seem to do anything.</p>
  
  <p>I also tried entering it directly</p>
  
  <pre><code>docker run -t -i -p 81:80 myImage /bin/bash
  </code></pre>
  
  <p>and from here I can start the service</p>
  
  <pre><code>service nginx start
  </code></pre>
  
  <p>and from another tab I can see it is working as intended (also in my browser):</p>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                NAMES
  408237a5e10b        myImage:latest      /bin/bash           12 seconds ago      Up 11 seconds       0.0.0.0:81-&gt;80/tcp   mad_turing 
  </code></pre>
  
  <p>So I assume it is something I am doing wrong with my Dockerfile? Could anyone help me out with this, I am quite new to Docker. Thank you!</p>
  
  <p><strong>SOLUTION:</strong> Based on the answer from Ivant I found another way to start nginx in the foreground. My Dockerfile CMD now looks like:</p>
  
  <pre><code>CMD /usr/sbin/nginx -g "daemon off;"
  </code></pre>