Using just built container as service

I want to use my just built container as a service so that I can run unit-tests against its newly built APIs. Is this possible or is there a better way to do this??

ex. snippet

build:
  image: docker:18-git
  stage: build
  script:
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG

test:
  service: $IMAGE_TAG
  image: docker:18-git
  stage: test
  script:
    - docker run curlimages/curl http://$IMAGE_TAG:80/hello