To run Backstage and the Lighthouse plugin with Docker Compose we need three things
- Postgres so that Lighthouse has a place to store the data it generates.
- The Lighthouse Audit Service
docker-compose.yml file which allows them to run together and inter-communicate.
version: '3' services: db: image: postgres environment: POSTGRES_USER: backstage POSTGRES_DB: backstage POSTGRES_HOST_AUTH_METHOD: trust volumes: - ./data/db:/var/lib/postgresql/data backstage: image: spotify/backstage ports: - '3000:80' depends_on: - lighthouse lighthouse: image: spotify/lighthouse-audit-service environment: LAS_PORT: 3003 LAS_CORS: 'true' PGDATABASE: backstage PGUSER: backstage PGHOST: db ports: - '3003:3003' depends_on: - db
Some notes about the above:
- Do not use
POSTGRES_HOST_AUTH_METHOD=trustin a production setup. It’s fine for experimenting but it will allow absolutely any connection to your database. That would not be good in production or staging.
pgwill store the postgres data in a
datadirectory in the place you run
docker-compose upfrom. You can configure it to store the data somewhere else if you like.
backstagespecify that traffic to
localhost:3000on your machine should be forwarded to port
80on the Backstage container. This is slightly different to running Backstage with
yarn start, where you would expect Backstage to run directly on port
3000. When Backstage is dockerized it is put behind a basic nginx reverse proxy which listens on port
portssetting will replicate the behavior of
yarn startdespite the nginx proxy.
PGHOSTmust be set to
lighthouseservice so that Lighthouse can communicate with the postgres database. Docker networking supports using service names for networking like this.
lighthouseservice must expose the port
3003. This was surprising to me as I expected Backstage to communicate with Lighthouse via the Docker network rather than by using
localhoston my machine. However, it turns out that when you visit the Backstage Lighthouse plugin on
http://localhost:3000/lighthouse, requests to the Lighthouse Audit service actually originate from your browser rather than from the Backstage backend.
docker-compose.yml in a directory then run the following command to prepare postgres with a user and database for using Backstage.
docker-compose up db
Once it has stated that the “database system is ready to accept connections” you can kill the process and start everything together.
Once that settles down, Backstage will be available on localhost:3000.