Connect docker compose apps

A shipping container on the back of a large whale

Locally, I use Docker and WSL2 for development. Inevitably I need to connect multiple docker compose apps, this blog post details how.

If I’m reading data from an API, I might use the public instance of an API. However, as soon as I need to create, update, or delete data, the public API doesn’t work, I switch to using a local instance.

Connect docker compose apps

Connecting multiple docker compose apps is simple as soon as you know how. I’m sure there are multiple ways to do it but the following works for me.

To ensure two or more docker compose apps can see each other, I ensure they use the same network, add the network to each of the docker-compose.yml files as below.

networks:
    default:
        name: costs.network
        external: true

Before you run each of the apps you will need to create the new network, the syntax to create a network is as below.

docker network create [network-name]

If you named your network costs.network as per my example, you would create the network as below.

docker network create costs.network

Your apps will now be able to see each other, all you need now is the URI. The URI should be the service name, if you review the Costs to Expect API docker-compose.yml file, you will see that I have set the service name as costs.api.app, the URI to access the API is therefore http://costs.api.app.

Expose API requests

API inscription coming out from an open book, art style, digital technology

We all need to be more open with our customer’s data; where does it come from, how is it structured and used. Users should not be deterred from getting at their data and all our customers deserve more than a data dump. We are going to expose all the API requests on our apps, even our closed products.

Budget Pro

Budget Pro is our first commercial App under the Costs to Expect umbrella, it is not open source. It is the sibling to Budget, our free and open-source budgeting tool. Like everything under the Costs to Expect name, the App uses the Costs to Expect API. The Costs to Expect API is open source; it always has been and always will be.

Open

Being open is so important to us that anything we create which consumes the API, you could recreate for yourself. Our free Apps and game scorers are open source so you can extend them. We want you to use our tools but if you want to use your own, that is more than fine, over time we hope more developers will leverage our API. We appreciate that right now our API isn’t ready for prime time, we need to improve our test suite and finish rewriting our documentation.

One of our core philosophies is to be as open as possible. To support this, we will expose all API GET. HEAD and OPTIONS requests within Budget Pro. We don’t expose POST and PUT requests as you can’t review them after the fact without caching data which is troubling.

We are not gatekeeping your data. Ideally you will access your API data using out Apps, but you don’t need to. You can access the API directly, use an App created by another developer or create an App yourself, it is up to you.

Requests table

At the bottom of each page there will be a table which shows any API requests that were made to generate the page. The table will show the URI, request method, the response time, and some other nerdy values. To see an example, please check out our social experiment, it has been showing the same data since 2019. Budget shows similar data when you are signed-in. When we update our game scorers, we will add the same requests table.

We appreciate that to many users; this data is redundant. However, over time we believe the number of users who care will increase significantly. In the long term we think our effort will be appreciated and we hope to not be in the minority of Apps showing the data.