Running with Docker
Relevant source files
The following files were used as context for generating this wiki page:
The Analog project utilizes Docker to manage its PostgreSQL database dependency, ensuring a consistent and simplified development environment setup. Docker Desktop is a prerequisite for running the application locally. This approach encapsulates the database service, allowing developers to start, stop, and manage it with simple commands without needing to install and configure PostgreSQL manually.
The core of this system is the docker-compose.yml file, which defines the PostgreSQL service. The project provides a set of npm scripts to interact with Docker Compose, streamlining the entire database setup process. This allows developers to focus on building the application while the database runs in an isolated container.
Sources: README.md:18-20, README.md:73-77
Architecture Overview
Docker is used exclusively for running the PostgreSQL database required by the Analog application. The Next.js web application, running on the local host machine, connects to this containerized database.
The following diagram illustrates the high-level architecture:
This diagram shows that the Next.js application, managed by the Bun runtime, communicates with the PostgreSQL database running inside a Docker container.
Sources: README.md:18-20, README.md:73-77, turbo.json:5-6
Docker Compose Configuration
The project uses a docker-compose.yml file to define and configure the PostgreSQL service. While the exact contents of this file are not provided, its function is to spin up a PostgreSQL container. Based on standard practices and project documentation, the service would be configured with a specific PostgreSQL image, environment variables for configuration, and port mappings.
The DATABASE_URL environment variable in the .env file must correspond to the connection string for this Docker container.
Sources: README.md:40-41, README.md:73-77
Inferred Service Definition
An illustrative docker-compose.yml for a PostgreSQL service would look similar to this:
# This is an illustrative example based on project documentation.
# The actual docker-compose.yml file is not provided in the context.
services:
postgres:
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=analog
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
This configuration defines a service named postgres, maps the container's port 5432 to the host's port 5432, and sets up a persistent volume for the data.
Sources: README.md:40-41, README.md:73-77
Management Scripts
The root package.json file provides several scripts to manage the Docker container's lifecycle. These scripts act as shortcuts for docker compose commands.
| Script | Command | Description |
|---|---|---|
docker:up | docker compose up -d | Starts the services defined in docker-compose.yml in detached mode. |
docker:down | docker compose down | Stops and removes the containers, networks, and volumes. |
docker:clean | docker compose down -v | Stops and removes containers, and additionally removes named volumes. |
Sources: package.json:8-10
Developer Workflow
To get the application running, a developer follows a specific sequence of steps where starting the Docker container is a crucial part.
The following flowchart outlines the complete setup process:
This workflow highlights that bun run docker:up must be executed successfully before the database can be initialized with bun run db:push and the application can be started.
Sources: README.md:22-91, CONTRIBUTING.md:10-63
Sequence of Starting the Database
The bun run docker:up command initiates a sequence of actions managed by Docker Compose.
This diagram shows the interaction between the user, the Bun script runner, Docker Compose, and the Docker Engine to bring the PostgreSQL container online.
Sources: package.json:8, README.md:76-77
Summary
Docker plays a vital but focused role in the Analog project's development environment. By containerizing the PostgreSQL database, it abstracts away the complexities of database installation and management. The provided npm scripts further simplify the process, allowing developers to set up, run, and tear down the necessary database service with single commands, which is a key part of the documented contribution and setup guides.
Sources: README.md, package.json, CONTRIBUTING.md