Deployment Overview of Strapi on Server¶
Prerequisites and Basic Requirements¶
The deployment requires a Linux-based operating system with root privileges. The following components must be available on the server:
- Docker Engine installed and running.
- A valid domain name configured to point to the server's IP address.
- Port
1337available for the Strapi application. - Port
5432available for the PostgreSQL database. - Ports
80and443available for the Nginx proxy and SSL termination.
File and Directory Structure¶
The application and its supporting services utilize the following directory structure on the host system:
/root/nginx: Contains the Nginx and Certbot configuration files and the Docker Compose definition./root/nginx/compose.yml: The Docker Compose file defining the Nginx service./data/nginx/nginx-certbot.env: Environment file containing Nginx-specific variables./data/nginx/user_conf.d: Directory for custom Nginx configuration snippets./data/nginx/nginx_secrets: External volume storing Let's Encrypt SSL certificates./var/lib/postgresql/data: Persistent storage location for the PostgreSQL database./srv/app: Mount point for the Strapi application data within the container.
Application Installation Process¶
The Strapi application is deployed using Docker containers. The installation involves setting up a dedicated Docker network and launching two primary services: a PostgreSQL database and the Strapi application.
- Strapi Image: The application uses the image
docker-repo.hostkey.com/docker-anonymous/strapi:latest. - PostgreSQL Image: The database uses the image
postgres:15. - Network: Both containers are connected to a custom Docker network to facilitate internal communication.
- Restart Policy: Both containers are configured with a
alwaysrestart policy to ensure high availability.
Docker Containers and Their Deployment¶
The deployment utilizes Docker to manage the application and database services. The containers are configured with specific environment variables and volume mounts.
PostgreSQL Container Configuration: - Name: Defined by the db_host variable. - Image: postgres:15. - Environment Variables: - POSTGRES_DB: Database name. - POSTGRES_USER: Database user. - POSTGRES_PASSWORD: Database password. - Volumes: The host directory /var/lib/postgresql/data is mounted to /var/lib/postgresql/data inside the container for data persistence. - Ports: The host port defined by db_port is mapped to container port 5432.
Strapi Container Configuration: - Name: strapi. - Image: docker-repo.hostkey.com/docker-anonymous/strapi:latest. - Environment Variables: - DATABASE_CLIENT: Set to postgres. - DATABASE_NAME: Matches the PostgreSQL database name. - DATABASE_HOST: Set to the internal hostname of the PostgreSQL container. - DATABASE_PORT: Set to 5432. - DATABASE_USERNAME: Matches the PostgreSQL user. - DATABASE_PASSWORD: Matches the PostgreSQL password. - Volumes: The host directory defined by strapi_volume is mounted to /srv/app inside the container. - Ports: The host port defined by strapi_port is mapped to container port 1337.
Proxy Servers¶
Nginx is deployed as a reverse proxy to handle incoming traffic and manage SSL certificates using Certbot.
- Image:
jonasal/nginx-certbot:latest. - Restart Policy:
unless-stopped. - Network Mode: Configured to use
hostnetworking. - Environment:
CERTBOT_EMAIL: Set to[email protected].- Loads additional configuration from
/data/nginx/nginx-certbot.env. - Volumes:
nginx_secrets: An external volume mounted to/etc/letsencryptfor storing SSL certificates./data/nginx/user_conf.d: Mounted to/etc/nginx/user_conf.dfor custom Nginx configurations.
The Nginx service is managed via a Docker Compose file located at /root/nginx/compose.yml.
Starting, Stopping, and Updating¶
The services are managed using Docker and Docker Compose commands.
Starting the Nginx Proxy: To start the Nginx and Certbot services, navigate to the configuration directory and run:
Verifying Container Status: To verify that the Strapi and PostgreSQL containers are running, execute:
Stopping Services: To stop the Nginx proxy services:
To stop the Strapi and PostgreSQL containers individually:
Updating Services: To update the Strapi application to the latest version, pull the new image and restart the container:
To update the PostgreSQL database:
To update the Nginx proxy: