Docker Environment for DatAscend
Application development with Docker Compose
Section titled “Application development with Docker Compose”The Docker Compose file is designed to provide a complete development environment for a the application. It includes a PostgreSQL database, a database seeding service, and the main application container.
Services
Section titled “Services”The compose file defines three primary services:
-
Database service
- Image:
postgres:latest- Uses the latest PostgreSQL image from Docker Hub. - Container Name:
da-database- A descriptive name for the database container. - Healthcheck: Implements a health check to ensure the database is fully operational before dependent services start.
- Environment:
CONTAINER=TEST: Sets a test environment flag, potentially used by scripts within the container.POSTGRES_PASSWORD=postgres: Sets the PostgreSQL password topostgres. Important: This is for development/testing purposes only and should not be used in production.
- Ports: Maps port
54320on the host to port5432inside the container. This allows accessing the database usinglocalhost:54320from the host machine.
- Image:
-
Database seeding service
- Image:
postgres:latest- Uses the latest PostgreSQL image to run the database seed script. - Container Name:
da-seed-database- Clearly names the container responsible for database seeding. - Command:
["/data/scripts/seed_db.sh", "/data/database"]- Executes theseed_db.shscript located in the mounted project directory. The second argument/data/databaseis a parameter passed to the script, potentially containing data or configuration needed for seeding. - Depends On:
database- Ensures that thedatabaseservice is healthy before thedatabase_scriptstarts, guaranteeing the availability of the database. - Volumes: Mounts the current project directory (
..) on the host into the/datadirectory inside the container, making project scripts and data accessible. - Environment: Sets environment variables required for database access, including connection details that target the
databaseservice using its service name. These ensure the seeding script can connect to the database correctly.
- Image:
-
Application service
- Image:
node:16.16.0- Uses Node.js 16.16.0 for running the application. - Container Name:
da-application- Clearly names the container that runs the main application. - Working Dir:
/data- Sets the working directory for the container to/datawhich is where the code is mounted. - Command:
/bin/bash -c "chmod +x /data/scripts/entrypoint.sh && /data/scripts/entrypoint.sh"- Executes theentrypoint.shscript after setting execution permissions. This script will likely start the application’s main process. - Depends On:
database: Ensures the database is healthy before starting the application.database_script: Ensures the database seeding process has completed successfully before starting the application, preventing application startup issues related to missing initial data.
- Volumes:
backend_modules:/data/backend/node_modules: Defines a named volume for backend node modules.project:/data: Binds the host directory to/datainside the container. This ensures code changes on the host are directly reflected within the container.
- Ports: Maps port
4000on the host to port4000inside the container. This allows accessing the application throughlocalhost:4000from the host machine. - Environment: Sets up environment variables for the application, including database connection details and application configuration. This environment makes the container aware of its test mode and database connection parameters.
- Image:
Volumes
Section titled “Volumes”The following named volumes are defined for data cache and code synchronization:
backend_modules: A named volume used to persist the/backend/node_modulesdirectory between container restarts.project: A bind mount that directly links the current project directory on the host to the/datadirectory inside the containers. This ensures that code changes are immediately available inside the containers without rebuilding the image.
To start the application, navigate to the directory containing this docker-compose.yml file and run:
docker-compose -f ./Dockerfiles/docker-compose.yml up -dNote: Any environment variables required by the application could be set by adding them to this command, this allows for easy testing of different database configurations, environments, etc.