<p>I have a problem. In my kubernetes cluster, I am trying to run my Rails application. I got the image loaded, but now I want to write a custom command. The default command in my Dockerfile is:</p>
<pre><code>CMD [&quot;bundle&quot;, &quot;exec&quot;, &quot;rails&quot;, &quot;server&quot;, &quot;-b&quot;, &quot;0.0.0.0&quot;]
</code></pre>
<p>But I want to also run <code>rails assets:precompile</code> at startup for production. I tried those commands using this config:</p>
<pre><code>command: [&quot;bundle&quot;, &quot;exec&quot;, &quot;rails&quot;, &quot;assets:precompile&quot;, &quot;&amp;&amp;&quot;, &quot;bundle&quot;, &quot;exec&quot;, &quot;rails&quot;, &quot;server&quot;]
</code></pre>
<p>But after the first command has been executed, I get the error:</p>
<pre><code>rails aborted!
Don't know how to build task '&amp;&amp;' (See the list of available tasks with `rails --tasks`)
</code></pre>
<p>I also tried the following with <code>args</code>:</p>
<pre><code>command: [&quot;/bin/sh -c&quot;]
args: 
  - bundle exec rails assets:precompile;
    bundle exec rails server;
</code></pre>
<p>But that results in a very long error which basicly says that the format of args is incorrect. Can someone explain to me how I can run both commands at startup?</p>

<p>Use <code>entrypoint</code> for that:</p>
<pre><code>services:
  app:
    build: .
    entrypoint: ./entrypoint.sh
    command: bundle exec rails s -p 3000 -b 0
    ports:
      - 3000:3000
</code></pre>
<pre class="lang-bash prettyprint-override"><code># entrypoint.sh

#!/bin/bash
set -e
# is this still an issue?
rm -f /myapp/tmp/pids/server.pid

# do what you have to do
bin/rails assets:precompile

# pass the torch to `command:`
exec &quot;$@&quot;
</code></pre>
<hr />
<p>Also the lazy way:</p>
<pre><code>    command: bash -c &quot;bin/rails assets:precompile &amp;&amp; bin/rails s -p 3000 -b 0&quot;
</code></pre>
<hr />
<p>You can also use <code>ENTRYPOINT</code> in <em>Dockerfile</em> and build it into the image:</p>
<pre><code>COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT [&quot;entrypoint.sh&quot;]
</code></pre>
