Deployment Overview of Strapi on Server¶
Prerequisites and Basic Requirements¶
The server must meet the following requirements to host the Strapi application and its associated services:
-
Operating System: Ubuntu (compatible with the Docker installation role).
-
Privileges: Root or sudo access is required to create directories, manage Docker, and configure the firewall.
-
Domain: The deployment utilizes the
hostkey.inzone. -
Ports:
-
Port
1337is used for the internal Strapi application. -
Port
5432is used for the PostgreSQL database. -
Ports
80and443are utilized by the Nginx proxy for HTTP and HTTPS traffic.
FQDN of the Final Panel¶
The application is accessible via the following Fully Qualified Domain Name (FQDN) structure:
strapi<Server ID>.hostkey.in:1337
Note: The actual external access may be routed through the Nginx proxy on standard ports (80/443) depending on the proxy configuration, while the direct container port is 1337.
File and Directory Structure¶
The deployment utilizes the following directories for application data, configuration, and certificates:
-
/opt/strapi: Primary volume for the Strapi application data and code. -
/root/nginx: Directory containing the Nginx and Certbotdocker-compose.ymlconfiguration. -
/etc/letsencrypt: Directory mounted for SSL/TLS certificates managed by Certbot. -
/data/nginx/user_conf.d: Directory for custom Nginx user configurations. -
/data/nginx: Directory containing the environment filenginx-certbot.env. -
/var/lib/postgresql/data: Directory for PostgreSQL persistent data storage.
Application Installation Process¶
The application is deployed using Docker containers. The installation includes the Strapi instance and a PostgreSQL database container, orchestrated within a dedicated Docker network.
-
Strapi Image:
docker-repo.hostkey.com/docker-anonymous/strapi:latest -
PostgreSQL Image:
postgres:15 -
Docker Network:
strapi_network
The deployment process involves:
-
Creating the necessary volume directory at
/opt/strapi. -
Establishing the Docker network
strapi_network. -
Launching the PostgreSQL container with specified environment variables.
-
Launching the Strapi container connected to the same network and database.
Databases¶
The application uses a PostgreSQL database for data persistence. The database is hosted within a Docker container named strapi-db.
-
Database Host:
strapi-db -
Database Port:
5432 -
Database Name:
strapi -
Database User:
strapi_user -
Database Password:
strapi_password -
Storage Location: Data is persisted in
/var/lib/postgresql/dataon the host.
The Strapi container connects to the database using the following environment variables:
-
DATABASE_CLIENT: postgres -
DATABASE_HOST: strapi-db -
DATABASE_PORT: 5432 -
DATABASE_USERNAME: strapi_user -
DATABASE_PASSWORD: strapi_password
Docker Containers and Their Deployment¶
The system utilizes the following Docker containers:
-
strapi-db
-
Image:
postgres:15 -
Restart Policy:
always -
Network:
strapi_network -
Volume: Maps
/var/lib/postgresql/datato/var/lib/postgresql/datainside the container. -
Ports: Exposes
5432mapped to host port5432. -
strapi
-
Image:
docker-repo.hostkey.com/docker-anonymous/strapi:latest -
Restart Policy:
always -
Network:
strapi_network -
Volume: Maps
/opt/strapito/srv/appinside the container. -
Ports: Exposes
1337mapped to host port1337. -
nginx (Proxy and SSL)
-
Image:
jonasal/nginx-certbot:latest -
Restart Policy:
unless-stopped -
Network Mode:
host -
Volumes:
-
nginx_secretsmapped to/etc/letsencrypt -
/data/nginx/user_conf.dmapped to/etc/nginx/user_conf.d
-
-
Configuration File:
/root/nginx/compose.yml
Proxy Servers¶
The deployment includes an Nginx reverse proxy with automatic SSL certificate management via Certbot.
-
Proxy Image:
jonasal/nginx-certbot:latest -
Email for Certbot:
[email protected] -
Configuration Location:
/root/nginx/compose.yml -
Environment File:
/data/nginx/nginx-certbot.env -
Volume Mounts:
-
nginx_secrets(external volume) mounted to/etc/letsencrypt. -
Host directory
/data/nginx/user_conf.dmounted to/etc/nginx/user_conf.d. -
Network Mode: The Nginx container runs in
hostnetwork mode.
The proxy handles traffic forwarding and SSL termination for the Strapi application.
Permission Settings¶
File and directory permissions are configured as follows:
-
Strapi Volume (
/opt/strapi): -
Owner:
1000(User ID) -
Group:
1000(Group ID) -
Mode:
0755(rwxr-xr-x) -
Nginx Directory (
/root/nginx): -
Owner:
root -
Group:
root -
Mode:
0755 -
Docker Compose File (
/root/nginx/compose.yml): -
Owner:
root -
Group:
root -
Mode:
0644
Location of Configuration Files and Data¶
The key configuration files and data locations are:
| File/Directory Path | Description |
|---|---|
/root/nginx/compose.yml | Docker Compose configuration for Nginx and Certbot. |
/data/nginx/nginx-certbot.env | Environment variables for the Nginx/Certbot container. |
/opt/strapi | Persistent storage for Strapi application data. |
/var/lib/postgresql/data | Persistent storage for PostgreSQL database data. |
/etc/letsencrypt | Storage for SSL/TLS certificates (via volume mount). |
Available Ports for Connection¶
The following ports are exposed and available for connection:
-
Port 1337: Direct access to the Strapi application container.
-
Port 5432: Direct access to the PostgreSQL database container.
-
Port 80: HTTP traffic handled by the Nginx proxy.
-
Port 443: HTTPS traffic handled by the Nginx proxy with SSL.
Starting, Stopping, and Updating¶
The services are managed using Docker commands.
Nginx Proxy Management: To start, stop, or update the Nginx proxy and Certbot services, execute commands from the /root/nginx directory:
Strapi and Database Management: The Strapi and database containers are managed directly via Docker commands:
# Start containers
docker start strapi strapi-db
# Stop containers
docker stop strapi strapi-db
# Restart containers
docker restart strapi strapi-db
# Update images
docker pull docker-repo.hostkey.com/docker-anonymous/strapi:latest
docker pull postgres:15
docker update strapi strapi-db
The restart_policy is set to always for both the Strapi and strapi-db containers, ensuring they automatically restart upon system reboot or crash.