Docker Environment Setups

This document explains how to use the environment configuration setup for different deployment scenarios including development, production, and staging environments.

This document explains how to use the environment configuration setup for different deployment scenarios including development, production, and staging environments.


Hugo Environment Setup

This document explains how to use the environment configuration setup for different deployment scenarios.

Environment Structure

We’ve organized environment configurations into separate files in the env directory:

  • env/.env.development - Development environment settings
  • env/.env.production - Production environment settings
  • env/.env.staging - Staging environment settings

Installation

To set up the environment structure, run:

1./scripts/install-env-setup.sh

This script will:

  1. Create the env directory with environment files
  2. Create helper scripts in the scripts directory
  3. Set up a symlink from .env to the development environment file

Using Different Environments

Method 1: Helper Functions

Source the helper functions:

1source scripts/env-helpers.sh

Then use the following commands:

  • hugo-dev - Start the development server
  • hugo-prod - Start the production server
  • hugo-staging - Start the staging server
  • hugo-build-prod - Build the production site
  • hugo-build-staging - Build the staging site
  • hugo-env - Show the current environment
  • hugo-stop - Stop all containers
  • hugo-cleanup - Clean up Docker resources

Method 2: Manual Environment Selection

You can manually specify the environment file when running Docker Compose:

1# Development
2ENV_FILE=env/.env.development docker compose up -d server
3
4# Production
5ENV_FILE=env/.env.production docker compose up -d server
6
7# Staging
8ENV_FILE=env/.env.staging docker compose up -d server

You can change the default environment by updating the symlink:

1# Switch to production
2ln -sf env/.env.production .env
3
4# Switch to development
5ln -sf env/.env.development .env
6
7# Switch to staging
8ln -sf env/.env.staging .env

Then run Docker Compose normally:

1docker compose up -d server

Environment Configuration Details

Development Environment

  • Port: 2003
  • Memory: 24GB
  • CPU: 4 cores
  • Drafts: Enabled
  • Verbose logging: Enabled
  • Config: config/development/hugo.yaml

Production Environment

  • Port: 3003
  • Memory: 24GB
  • CPU: 4 cores
  • Drafts: Disabled
  • Verbose logging: Disabled
  • Minification: Enabled
  • Config: config/production/hugo.yaml

Staging Environment

  • Port: 4003
  • Memory: 24GB
  • CPU: 4 cores
  • Drafts: Enabled (for review)
  • Verbose logging: Disabled
  • Minification: Enabled
  • Config: config/production/hugo.yaml

Customizing Environments

You can customize any environment by editing the corresponding file in the env directory. Common settings to adjust include:

  • HUGO_DEV_PORT - The port to access the server
  • DOCKER_MEMORY_LIMIT - Memory allocation for the container
  • DOCKER_CPU_LIMIT - CPU allocation for the container
  • HUGO_BUILDDRFTS - Whether to include draft content
  • HUGO_VERBOSE - Enable verbose logging
  • HUGO_MINIFY - Enable minification

Testing Environments

To test if your environment configuration is working correctly:

  1. Start a server with a specific environment:

    1ENV_FILE=env/.env.production docker compose up -d server
    
  2. Check the server is running on the expected port:

    1curl http://localhost:3003
    
  3. Check the container’s resource allocation:

    1docker stats
    
  4. Verify the Hugo configuration being used:

    1docker compose logs server | grep "config"
    

Troubleshooting Docker Issues

 1docker logs docker-with-hugo-server-1
 2
 3# Using curl
 4curl http://localhost:2003
 5
 6# Using curl
 7curl http://localhost:2003
 8
 9curl http://localhost:2003 | head -20
10
11# Check if anything is listening on port 2003
12netstat -tuln | grep 2003
13
14# Using wget
15wget -O- http://localhost:2003
16
17sudo ufw status
18
19sudo ufw allow 2003/tcp
20
21# Find your IP
22ip addr show | grep -E "inet .* global" | awk '{print $2}' | cut -d/ -f1
23
24sudo lsof -i :2003
25
26docker exec hugo-dev-server-1 env | grep HUGO
  • docker logs docker-with-hugo-server-1: Displays the logs of the Docker container named docker-with-hugo-server-1. Useful for debugging or monitoring the container’s output.
  • curl http://localhost:2003: Sends an HTTP GET request to localhost on port 2003. This checks if the server is responding.
  • curl http://localhost:2003 | head -20: Sends an HTTP GET request to localhost on port 2003 and displays the first 20 lines of the response. Useful for quickly inspecting the server’s output.
  • netstat -tuln | grep 2003: Checks if any process is listening on port 2003. The -tuln flags show TCP/UDP connections in numeric form.
  • wget -O- http://localhost:2003: Fetches the content from http://localhost:2003 and outputs it directly to the terminal (-O-).
  • sudo ufw status: Displays the status of the UFW (Uncomplicated Firewall) to check which ports are open or blocked.
  • sudo ufw allow 2003/tcp: Opens port 2003 for TCP traffic in the UFW firewall, allowing external connections.
  • ip addr show | grep -E "inet .* global" | awk '{print $2}' | cut -d/ -f1: Finds the system’s global IP address by filtering the output of ip addr show.
  • sudo lsof -i :2003: Lists all processes using port 2003. Useful for identifying which application is bound to the port.
  • docker exec hugo-dev-server-1 env | grep HUGO: Executes the env command inside the Docker container hugo-dev-server-1 and filters for environment variables containing HUGO.

FAQs