title: Knex Migration with Docker Compose Psql
body: <p>I have a problem migrating using Knex js inside my docker-compose container.
   the problem is that npm run db (knex migrate:rollback &amp;&amp; knex migrate:latest &amp;&amp; knex seed:run) would run right before the database is even created. Is there anyway to say that I would only like to run npm run db after the database has been created? </p>
  
  <p>NOTE : if I do this npm commands on the docker terminal after it has been built everything works fine. just fyi</p>
  
  <p>here is my docker-compose.yml</p>
  
  <pre><code>version: '3.6'
  
  services:
    #Backend api
    server:
      container_name: server
      build: ./
      command: npm run db
      working_dir: /user/src/server
      ports:
        - "5000:5000"
      volumes:
        - ./:/user/src/server
      environment:
        POSTGRES_URI: postgres://test:test@192.168.99.100:5432/interapp
      links:
        - postgres
  
    # PostgreSQL database
    postgres:
      environment:
        POSTGRES_USER: test
        POSTGRES_PASSWORD: test
        POSTGRES_DB: interapp
        POSTGRES_HOST: postgres
      image: postgres
      ports:
        - "5432:5432"
  </code></pre>
  
  <p>and here is my Dockerfile</p>
  
  <pre><code>FROM node:10.14.0
  
  WORKDIR /user/src/server
  
  COPY ./ ./
  
  RUN npm install
  
  CMD ["/bin/bash"]
  </code></pre>