title: If a service is started during docker build, should it be running at runtime?
body: <p>I have been working on setting up a self contained rails app in a single container. This means getting both rails and a data persistence service running at the same time in one container. In our case, that means mysql.</p>
  
  <p>However, I ran into multiple issues getting this working, because mysql wasn't running.</p>
  
  <p>During the build step, if I had <code>RUN mysqld</code> and then a separate <code>RUN rake db:create</code> step, rake would crash, because mysql was down.</p>
  
  <p>So I worked around this by wrapping the two commands into a script. However, at runtime, rails would fail to startup because mysql wasn't running.</p>
  
  <p>My intuition says that if mysql is started during the build, it should be available at runtime, but I did not have that experience. Starting the rails server had to be wrapped in a script with another call to <code>mysqld</code>.</p>
  
  <p>Here's the dockerfile:</p>
  
  <pre><code>FROM ruby:2.2
  RUN mkdir -p $APPDIR
  WORKDIR $APPDIR
  ADD Gemfile* $APPDIR/
  RUN bundle install
  RUN apt-get update -qq
  RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nodejs mysql-server --no-install-recommends
  RUN rm -rf /var/lib/apt/lists/* # */ broken syntax highlighting
  COPY . $APPDIR
  RUN script/mysql-setup.sh # contents are: mysqld_safe; rake db:create; rake db:migrate
  EXPOSE 3000
  CMD ["script/rails-launcher.sh"] # contents are: mysqld_safe; rails s
  </code></pre>
  
  <p>Do I need to do something differently in the Dockerfile? Why isn't mysql up at runtime?</p>