Docker and Docker Compose
Relevant source files
The following files were used as context for generating this wiki page:The Quix project utilizes Docker for containerization, providing a consistent and isolated environment for both development and deployment. This is managed through a Dockerfile for building the application image and a docker-compose.local.yml file for orchestrating a multi-container local development setup.
This document provides an overview of the Docker setup, including how to build and run the application using both standalone Docker commands and Docker Compose.
Standalone Docker Usage
The primary method for packaging the Quix application is through a multi-stage Dockerfile. This approach creates an optimized, smaller final image by separating the build environment from the runtime environment.
Sources: README.md:118-124
Dockerfile Breakdown
The build process is divided into two main stages: builder and the final runtime stage.
This diagram illustrates the multi-stage build process defined in the Dockerfile.
Sources: package.json:12, link.sh
Stage 1: builder
This stage is responsible for setting up the development environment and building the application source code.
- It starts from a Node.js base image.
- It copies
package.json,yarn.lock, and thelink.shscript. - It installs all project dependencies using
yarn install. - It runs the
link.shscript to symlink the localagent-packages. - It copies the rest of the source code.
- Finally, it builds the application using the
yarn buildscript defined inpackage.json.
Sources: package.json:12, link.sh
Stage 2: Final Image
This stage creates the lean, production-ready image.
- It starts from a slim Node.js base image.
- It copies the compiled code from the
distfolder and thenode_modulesdirectory from thebuilderstage. - It exposes port
3000, which is the default port for the application. - The
CMDinstruction is set to run the production start command,yarn start:prod.
Sources: package.json:15, src/lib/constants.ts:1-3
Building and Running the Image
The README.md file provides instructions for building and running the Docker image.
Build Command
To build the image, run the following command from the project root:
docker build -t quix .
Sources: README.md:121
Run Command
To run the built image as a container, use the docker run command. You must provide an environment file to configure the application.
docker run -p 3000:3000 --env-file .env quix
This command maps port 3000 on the host to port 3000 in the container and passes environment variables from a .env file.
Sources: README.md:124
Local Development with Docker Compose
For local development, the docker-compose.local.yml file simplifies the process of running the application along with its dependencies (PostgreSQL and Redis).
Sources: README.md:126-128
Service Architecture
The Docker Compose setup defines three services: api, db, and redis. The api service depends on db and redis to be running.
The diagram below shows the relationship between the services defined in docker-compose.local.yml.
Service Definitions
The docker-compose.local.yml file configures the services required for a complete local environment.
| Service | Image/Build | Ports | Volumes | Depends On | Description |
|---|---|---|---|---|---|
| api | Builds from local Dockerfile | 3000:3000 | .:/usr/src/app | db, redis | The main Quix Nest.js application. The volume mounts the local source code for live-reloading. |
| db | postgres:15 | 5432:5432 | postgres_data:/var/lib/postgresql/data | - | The PostgreSQL database service. The volume ensures data persistence across container restarts. |
| redis | redis:latest | 6379:6379 | - | - | The Redis service used for caching. |
Usage
To start all services for local development, run the following command:
docker-compose -f docker-compose.local.yml up
This command will build the api image if it doesn't exist and then start all three services.
Sources: README.md:128
Summary
The Quix repository is fully equipped for containerized development and deployment. The Dockerfile provides a reproducible, multi-stage build process for creating an optimized production image. For local development, the docker-compose.local.yml file orchestrates the main application along with its database and cache dependencies, offering a simple one-command setup. This dual approach ensures consistency between development and production environments, simplifying both setup and deployment.