This is expected behaviour from Docker.
In Gitlab CI, all services you define will be linked with your container which is running your job using Docker linking system.
As describe here, when we link containers, Docker automatically creates ENVs in format:
- <_alias>_NAME
- <_alias>_PORT
- and some other ENVS
And those ENVs from Docker will override yours.
alias here will be the hostname of your container you defined in services. For example your define these services in your .gitlab-ci.yml:
services:
- redis:5-alpine
- name: mongo
alias: db
So Docker will create the following ENVs respectively:
- REDIS_PORT="some thing looks like: tcp://172.17.0.3:6379"
- REDIS_NAME="looks like: /runner-72989761-project-19846207-concurrent-0-62507216079cf651-build-3/redis"
- DB_PORT=same like redis
- DB_NAME=same like redis
And note that, as described here, by default the following ENVs are also auto created based on service image's name:
- MONGO_PORT=...
- MONGO_NAME=...
So in your code if you have any variable that has same name with the ones Docker creates, you may need to change your variable's name otherwise it'll be override by Docker. Or you can pass variables in your Gitlab CI config file to override what Docker does, like this:
services:
- redis:5-alpine
- name: mongo
alias: db
variables:
REDIS_PORT: 6379
DB_NAME: api-gateway