In some applications, you might need a file to be present at a certain path for the application to work. Or you have data in directories that need to be mounted for the application to work. You can mount data to your service either by mounting a volume, secret or a string.

If your application needs access to multiple files of data or multiple directories, you can use a volume to store the data and then mount the volume at the desired path. You can learn more about Volumes here. To use a persistent volume, we will first need to create one and then attach it to your deployment. You can learn how to create volumes using the Creating a Volume guide.

You can only mount volumes in the same workspace as your service.

Using mounted files in your deployment

Once you have attached a file to your deployment, you can use it in your deployment like any other file. For example, if you mounted the file to /etc/config.json, you can access the file in the /etc/config.json path

import json

with open("/etc/config.json", "r") as f:
  config_data = json.load(f)

# Access specific values from the config data dictionary
api_key = config_data["api_key"]
database_url = config_data["database_url"]

# Use these values in your application logic
print(f"API key: {api_key}")
print(f"Database URL: {database_url}")

In some applications, you might need a file to be present at a certain path for the application to work. Or you have data in directories that need to be mounted for the application to work. You can mount data to your service either by mounting a volume, secret or a string.

If your application needs access to multiple files of data or multiple directories, you can use a volume to store the data and then mount the volume at the desired path. You can learn more about Volumes here. To use a persistent volume, we will first need to create one and then attach it to your deployment. You can learn how to create volumes using the Creating a Volume guide.

You can only mount volumes in the same workspace as your service.

Using mounted files in your deployment

Once you have attached a file to your deployment, you can use it in your deployment like any other file. For example, if you mounted the file to /etc/config.json, you can access the file in the /etc/config.json path

import json

with open("/etc/config.json", "r") as f:
  config_data = json.load(f)

# Access specific values from the config data dictionary
api_key = config_data["api_key"]
database_url = config_data["database_url"]

# Use these values in your application logic
print(f"API key: {api_key}")
print(f"Database URL: {database_url}")