Wants an advise on Gitlab CI/CD with docker-compose for different stages

I am new to Gitlab CI/CD and I have been studying online myself such as GitLab CI CD Pipeline Tutorial | Introduction | 2022 - YouTube . I am up to the point that I understand there are multiple stages - each for different purposes such as build, test and deploy. From the initial template that uses echo to simulate what could be happening, I already got something like this in the .gitlab-ci.yml file:

image: docker/compose:latest

services:
  - docker:dind

before_script:
  - docker info
  - docker-compose --version

stages:
  - build
  - test
  - deploy

build-image:
  stage: build
  script:
    - docker-compose up -d --build

This returned successfully, and I see all the services in docker-compose do run.

My issue however is the next step. I will have a testing script that will curl http endpoints with parameters for automated testing purpose. Assuming it is a simple bash script for now for the sake of simplicity and learning.

I see that each stage is of its own environment and I will need to use pipeline artifacts to provide the stages access to each other. Thing is for my case, I am using docker-compose, so all the services are in docker environment. What must I do in this case to “persist docker services”?

Thank you