Gitlab-ci: provide environment variable(s) to custom docker image in a pipeline

I want to set up a test stage for my gitlab-ci which depends on a custom docker image. I want to know how will I provide some config (like setting env variable to providing a .env file) to it so that the custom image runs properly and hence the stage.
Current config:

test_job:
  only:
  refs:
    - master
    - merge_requests
    - web
stage: test
services:
  - mongo:4.0.4
  - redis:5.0.1
  - registry.gitlab.com/myteam/myprivaterepo:latest # Provide config to this image
variables:
  - PORT=3000
  - SERVER_HOST=myprivaterepo
  - SERVER_PORT=9090
script: npm test

I want to provide environment variables to myprivaterepo docker image which connects to mongo:4.0.4 and redis:5.0.1 services for its functioning.

The variables are MONGODB_URI="mongodb://mongo:27017/aics" and REDIS_CLIENT_HOST: "redis". These have no meaning for the app being tested but has meaning for the myprivaterepo image without which the test stage will fail.