title: Using a GitLab CI/CD pipeline, how can I run Cypress tests on the Front-End of a Docker-hosted Database?
body: <p>I'm building my very first web application with Vue.js and I'm using Docker to virtualize my server-side MySQL database (to provide a simple cloud save option for users) while developing. I also use Cypress to run E2E tests on my front end, including possible user interactions with the DB (or rather interactions with my API, which then sends corresponding requests to the DB). What I want to do now is create a GitLab pipeline that automatically runs my Cypress tests, which require the Docker DB to be running.</p>
  <p>When locally running my app I go through the following steps:</p>
  <ol>
  <li>I run my 3 Docker containers (Node.js API, MySQL DB, PHP Adminer) in a terminal via <code>docker-compose up</code> using my <em>docker-compose.yml</em>.</li>
  <li>I run my app in dev mode via <code>npm run serve</code>.</li>
  <li>Now that the Docker containers and the app are running, I can successfully run my Cypress tests with npm as well.</li>
  </ol>
  <p>Now I want to automate this whole process in a <em>.gitlab-ci.yml</em>. I was able to build the app and also run the Cypress tests, but I can't figure out how to run my Docker containers before running Cypress so that my tests can actually interact with the virtual DB. I simply tried adding the <code>docker-compose up</code> command to the script before calling Cypress, but then the pipeline fails because it doesn't know that command. I then went through different guides on how to import docker-compose to your pipeline but nothing has worked yet.</p>
  <p>Before trying any of those unsuccessful guides, my yml-file looked like this:</p>
  <pre><code>image: cypress/base:10
  
  stages:
    - test
    - build
  
  cache:
    paths:
      - node_modules/
  
  run_cypress:
    stage: test
    script:
      - cd docker
      - docker-compose up
      - cd ../code
      - npm install
      - npm run cypress:open
    artifacts:
      expire_in: 1 week
      when: always
      paths:
        - [redacted]
  
  build_code:
    stage: build
    script:
      - cd code
      - npm install
      - npm run build
  </code></pre>
  <p>As I said, this script fails at the <code>docker-compose up</code> line, but runs properly without it. The tests also execute properly with the custom <code>cypress:open</code> script, but most of them fail because without Docker the database isn't actually running, of course. So what do I need to add or change in order to make the script know <code>docker-compose</code> and to let it properly run Docker before executing the tests?</p>