title: How to run command conditionally in docker compose
body: <p>I want to run command conditionally in docker-compose</p>
  <p>because when someone run this application at first time,</p>
  <p>They would have to run <code>migrate</code> command so that they can run <code>django</code> application properly</p>
  <p>But If their docker have run <code>migrate</code>, there is no need to run <code>migrate</code> again</p>
  <p>So this is the command to check that their docker have run <code>migrate</code>.</p>
  <pre><code>    if [[ -z $(python3 zeus/manage.py showmigrations | grep '\[ \]')]]; then
          echo 'no need to migrate'
      else
          echo 'need to migate'
      fi
  </code></pre>
  <p>This is my docker-compose.</p>
  <pre><code>version: '3'
  
  services:
    db:
      image: postgres
    web:
      command: &gt;
           bash -c &quot;if [[ -z $(python3 zeus/manage.py showmigrations | grep '\[ \]')]]; then
                 echo 'no need to migrate'
              else
                 echo 'need to migate'
              fi &amp;&amp; python3 zeus/manage.py runserver 0.0.0.0:8000
           &quot;
  </code></pre>
  <p>But Error occurs like this</p>
  <pre><code>ERROR: Invalid interpolation format for &quot;build&quot; option in service 
  &quot;web&quot;: &quot;bash -c &quot;if [[ -z $(python3 zeus/manage.py showmigrations | grep '\[ \]')]]; then 
  echo 'no need to migrate' else echo 'need to migate' fi 
  &amp;&amp; python3 zeus/manage.py runserver 0.0.0.0:8000&quot;&quot;
  </code></pre>
  <p>Any idea?</p>
  <h2>Edit</h2>
  <p>This is fine when I run the script of checking migration in normal bash</p>
  <p>I think docker-compose can't parse <code>$(python3 manage.py .....)</code> part.</p>