Composition Service Discovery (Experimental)

Codefresh enables you to launch multiple instances of the same composition utilizing Docker. This is possible, in part, because Docker can map ports from a container to a random port on a host. Following from this are some basic questions:

  • If your container is mapped to a random port, how can you predict the URL of the application?
  • How can you configure your web application’s container with a “Base URL”?
  • How can you reference other services without linking to them?

This feature is available for users with a Pro subscription.
Already a Pro subscriber? Contact us to opt into this feature.

Codefresh utilizes Dynamic Composition Service Routing to deliver seamless service discovery within a composition.

After you enable this feature for your account, Codefresh injects the URLs of every service in your composition as environment variables.

What do these environment variables look like?

Every service URL environment variable is prefixed with CF_URL_ and is uniquely identifiable using the service name: CF_URL_SERVICENAME=

If your service exposes multiple ports, an environment variable will be injected for every port, and will be comprised of a combination of the service name and the service’s port: CF_URL_SERVICENAME_PORTNUMBER=

Also, every service would be having a domain that would direct to each service. The domains can be uniquely identifiable with environments variables:

For services that exposes multiple ports the environment variable should have the port number as a suffix:


The unique identifier is the service’s name, not the name of the container that was produced for the service.


Consider the following composition:


version: '3'
    image: postgres
    image: myorg/api
      - 9000
      - db
    image: myorg/web
      - 80
      - 8080

The db service does not expose any ports. The api service exposes port 9000, and the web service exposes port 80 and port 8080.

So, every container produced by this composition will be injected with:


This means you can also discover these URLs within your application. For example, within a Node.js application you can run the following routine:

Find all service URLs

const allVars = process.env;
const allUrls = Object.keys(allVars)
    .filter(envVarKey => envVarKey.startsWith('CF_URL_'))
    .reduce((obj, envVarKey) => {
        obj[envVarKey] = allVars[envVarKey];
        return obj;
    }, {});

The allUrls object will retain all the injected URL environment variables.