Overview
This section outlines the configuration options available for the helixml/base-images development environment, following the best practices for setting up and customizing the environment according to your needs.
Configuration Files
Configuration primarily takes place within specific files in your development setup. Below are the main files you may need to configure:
.env
docker-compose.yml
Dockerfile
1. Environment Variables (.env
)
The .env
file is used to set environment-specific variables that customize how the application runs within its containers. Below is a sample .env
file with commented examples of common configurations:
# Database configurations
DB_HOST=db
DB_PORT=5432
DB_USER=user
DB_PASSWORD=strongpassword
DB_NAME=example_db
# Application specific configuration
APP_ENV=development
APP_DEBUG=true
# API keys
API_KEY=your_api_key_here
After updating the .env
file, ensure your application has access to these variables within the codebases, such as by using a library like python-dotenv
:
from dotenv import load_dotenv
load_dotenv()
import os
db_user = os.getenv('DB_USER')
2. Docker Compose (docker-compose.yml
)
The docker-compose.yml
file manages the multi-container Docker applications. Here, you can specify the services, networks, and volumes that are necessary for your application. A simple configuration example is provided below:
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
environment:
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_NAME=${DB_NAME}
ports:
- "8000:8000"
volumes:
- .:/app
db:
image: postgres:latest
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
ports:
- "5432:5432"
In this configuration:
- The app service is built using a specified
Dockerfile
. - Environment variables are set from the
.env
file. - Port mapping allows access to the application on port 8000.
3. Dockerfile
The Dockerfile
defines the environment for the application. Here is an example that demonstrates how to set it up:
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the application code
COPY . .
# Command to run the application
CMD ["python", "app.py"]
This Dockerfile does the following:
- Starts with a base image of Python 3.9 slim.
- Sets the working directory to
/app
. - Installs Python dependencies from
requirements.txt
. - Copies the application source code into the container.
- Specifies the command to run the application.
Building and Running
Once configurations are in place, the development environment can be built and executed using the following shell commands:
# Build the Docker containers
docker-compose build
# Run the Docker containers
docker-compose up
To run the application in the background, append the -d
flag:
docker-compose up -d
Conclusion
The configuration of the helixml/base-images for a development environment involves customizing the .env
, docker-compose.yml
, and Dockerfile
to meet specific application requirements. Following the outlined examples will help ensure a successful setup tailored to your development needs.
Source
This configuration guide is created based on the helixml/base-images documentation.