Gitlab CI api_v4_url env variable problem

How to get the api url Gitlab runner uses to connect to the Gitlab instance? I’m trying to make my build scripts to be more versatile, so they could be built without any issues on any other Gitlab instance. CI_API_V4_URL env variable returns the external url, is there a different variable that has the runner’s configured url? (In this case its a local IP for the gitlab container inside of the docker network)