arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Installation with Docker

hashtag
Prerequisites

Before installing Prophecies, ensure you have the following tools installed:

  • Docker: A platform for developing, shipping, and running applications inside isolated environments known as containers. Learn more about Dockerarrow-up-right.

  • Docker Compose: A tool for defining and running multi-container Docker applications. It uses a YAML file to configure your application's services, making it easier to manage complex setups. .

These tools are essential for running Prophecies efficiently and are widely used in the development and deployment of modern applications.

hashtag
Setup steps

hashtag
1. Prepare the Working Directory

Place this docker-compose.yml file in your chosen directory. This will be the working directory for your Docker Compose setup:

hashtag
2. Configure NGINX

You need to create an NGINX configuration file as referenced in your Docker Compose file (./nginx.conf). Ensure this file is correctly configured to serve your Prophecies. It should be set up to listen on port 9999 and serve static files from the /static/ directory:

hashtag
3. Starting Services

In your working directory, run the following command:

This command will download the necessary images (if not already downloaded), create the defined volumes, and start the services as background processes.

hashtag
3. Database Migrations and Static Files

The docker-compose.yml file specifies services for running database migrations (migration) and collecting static files so they can be served by NGINX (collectstatic). These services should automatically perform these tasks when you start Docker Compose.

hashtag
4. Create Admin User

The database is currently empty, without user. To provision your first admin user, you must use the command line:

hashtag
5. Accessing the Application

Once all services are up and running, the application should be accessible via :

6. Monitoring and Logs

To monitor the status of your Docker containers and check for any issues, you can use the Docker Compose logs command:

The -f flag will follow the log output, allowing you to see real-time logs as they are generated.

7. Stopping and Removing Services

To stop the services without removing them, you can run:

If you need to stop and remove all the containers, networks, and volumes associated with your Docker Compose setup, use the down command:

triangle-exclamation

This will clean up everything you have created and is particularly useful for starting from scratch. Please make sure you know what you're doing before running this command.

hashtag
Additional Notes

  • This configuration doesn't include SSL setup for NGINX, which is recommended for production.

  • Regularly check for updates to the icij/prophecies image to keep your application up to date.

  • To use custom domain, don't forget to update the ALLOWED_HOSTS

variable.
  • The application can be configured with .

  • Get started with Docker Composearrow-up-right
    http://localhost:9999arrow-up-right
    version: '3'
    
    volumes:
      shared_static: {}
      postgresql_data: {}
    
    services:
      nginx:
          image: nginx:latest
          ports:
            - "9999:9999"
          volumes:
            - ./nginx.conf:/etc/nginx/conf.d/default.conf
            - shared_static:/static/:ro
          depends_on:
            - web
    
      web:
        image: icij/prophecies:0.5.9
        environment:
          - ALLOWED_HOSTS=0.0.0.0,localhost,web
          - CSRF_TRUSTED_ORIGINS=http://localhost:9999
          - DATABASE_URL=postgres://postgres:postgres@db/prophecies
          - DEBUG=false
          - DJANGO_SETTINGS_MODULE=prophecies.settings.production
          - DJANGO_ADMIN_LOGIN=true
          - PROPHECIES_APP_LOGIN_URL=/admin/login/?next=/
          - PORT=8008
          - WAIT_HOSTS_TIMEOUT=60
          - WAIT_HOSTS=db:5432
        volumes:
          - shared_static:/code/prophecies/run/static
        depends_on:
          - db
          - migration
          - collectstatic
        expose:
          - "8008"
    
      migration:
        image: icij/prophecies:0.5.9
        command: sh -c '/usr/bin/wait && poetry run python manage.py migrate --noinput'
        environment:
          - WAIT_HOSTS=db:5432
          - WAIT_HOSTS_TIMEOUT=60
          - DATABASE_URL=postgres://postgres:postgres@db/prophecies
        depends_on:
          - db
    
      collectstatic:
        image: icij/prophecies:0.5.9
        command: poetry run python manage.py collectstatic --noinput
        volumes:
          - shared_static:/code/prophecies/run/static
    
      db:
        image: postgres:16
        restart: always
        environment:
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
          POSTGRES_DB: prophecies
        command: postgres -c shared_preload_libraries=pg_stat_statements -c 'pg_stat_statements.track=all'
        volumes:
          - postgresql_data:/var/lib/postgresql/data
    upstream web {
      ip_hash;
      server web:8008;
    }
    
    server {
    
        location /static/ {
            autoindex on;
            alias /static/;
        }
    
        location / {
            proxy_pass http://web/;
        }
        
        listen 9999;
        server_name localhost;
    }
    
    docker compose up -d
    docker compose exec -it web make createsuperuser
    docker compose logs -f
    docker compose stop
    docker compose down --volumes
    many environment variables