Sharing consul service between apps

Hi there, is it possible to share a consul instance between two apps? I’ve tried attaching consul to one app, and then trying to connect to that consul instance from another app but the connection is reset

I also have this question.

Curious your use case. For me it’s that I want to have two separate apps sharing a LiteFS cluster, with one app only being a reader.

My use case is to have a KV store where I can store secrets that can be updated at runtime

I did do some further testing and it looks like the answer is yes, you can share the same Consul URL amongst your apps and it should work. In my case it wasn’t working in the container I was testing in, most probably due to a container issue (eg TLS version)

However, I realized I can use an existing Redis service instead so will no longer be needing Consul

Did you use consule attach in both places? Or use the same ENV in both place with the URL?


It’s app name specific, so is the idea that the app name is static for both apps you deployed?

I did fly consul attach in the first app, which generates a FLY_CONSUL_URL environment variable, you can then use this same value across your other apps.

It can be difficult to figure out how to use the URL, but basically you’ll have something like:


You then need to parse this URL and use the parts to facilitate requests to the Consul instance, e.g. for Consul’s KV API, you would do something like:

GET https://fly.consul.endpoint/v1/kv/appname-hash?keys
X-Consul-Token: token

For your use case though, you might be able to get away with just changing the values in litefs.yaml to be:

  type: consul
  candidate: false
  promote: false
    url: ${OTHER_CONSUL_URL}
    key: ${OTHER_APP_NAME}/primary

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.