Service Linking
Service linking automatically injects environment variables into workloads with connection information for other workloads in the same sandbox. This follows a convention common in platforms like Kubernetes, making it easy for services to discover each other without hardcoded configuration.
Service linking is enabled by default and can be disabled per workload.
Injected Environment Variables
For each workload with explicitly declared ports, the following environment variables are injected into all other workloads:
<HOSTNAME>_SERVICE_HOST=<hostname>
<HOSTNAME>_SERVICE_PORT=<first port number>
<HOSTNAME>_SERVICE_PORT_<PORT-NAME>=<port number>
Example
Given this sandbox definition:
workspaces:
- name: dev
dependencies:
- name: mysql
service_type: mysql
- name: redis
service_type: redis
containers:
- name: foo
image: foo
ports:
- name: http
port: 8000
protocol: HTTP/TCP
- name: api
port: 9000
protocol: GRPC/TCP
In the dev workspace, the following environment variables are automatically available:
| Variable | Value |
|---|---|
MYSQL_SERVICE_HOST |
mysql |
MYSQL_SERVICE_PORT |
3306 |
MYSQL_SERVICE_PORT_MYSQL |
3306 |
REDIS_SERVICE_HOST |
redis |
REDIS_SERVICE_PORT |
6379 |
REDIS_SERVICE_PORT_REDIS |
6379 |
FOO_SERVICE_HOST |
foo |
FOO_SERVICE_PORT |
8000 |
FOO_SERVICE_PORT_HTTP |
8000 |
FOO_SERVICE_PORT_API |
9000 |
Disabling Service Linking
Service linking can be disabled for a specific workload by adding disable_service_linking_envs: true:
workspaces:
- name: dev
disable_service_linking_envs: true
See Also
- Sandbox Networking — how workloads communicate by hostname
- Sandbox — workload types and port declarations