Services
Services are the main building blocks of the Ptah.sh system.
Processes
In Ptah.sh, services are composed of one or more “processes”. Each process represents a Docker Swarm Service and defines its own configuration and behavior.
For example, a PostgreSQL service in Ptah.sh may be defined as two processes: the PostgreSQL server itself and pgpool running as a sidecar container. Each of these processes would correspond to a separate Docker Swarm Service.
Workers
Workers represent individual Docker Swarm Services within a Ptah.sh Service. Each worker can be configured independently with its own settings, allowing for flexible and granular control over your application’s components.
Each worker can have the following configurations:
- Docker Image: Specify the Docker image to use for this worker.
- Registry: Choose between public registries or pre-configured private registries.
- Git Repository: Specify the Git repository to use for this worker.
- Replicas: Define how many instances of this worker should run.
- Launch Mode: Specify how and when this worker should be started (e.g., always, on-demand, or scheduled).
- Healthcheck: Configure health monitoring for the worker.
- Release Command: Set up commands to run before the main process starts.
- Command (Entrypoint): Define the main command to run for this worker.
This worker-based approach allows you to create complex, multi-component services where each component (worker) can be fine-tuned to your specific needs while maintaining a shared configuration base.
Learn more about workers in the Daemons and Workers page.
Volumes
Volumes are shared among all workers within a service. Each service may have a list of volumes that are mounted to its workers’ containers. These volumes are Docker Swarm volumes, which provide persistent storage for your services.
Docker Swarm volumes offer several benefits:
- Data persistence across container restarts
- Easy sharing of data between containers
- Improved performance compared to bind mounts
Volumes can be configured with different drivers, including local storage or network-attached storage solutions. Additionally, Ptah.sh supports backing up these volumes to S3-compatible storage, ensuring data durability and facilitating disaster recovery.
For more information on S3 storage integration, see the S3 Storages page.
Environment Variables
Environment variables are shared among all workers within a service. Each service may have a list of environment variables that are set on its workers’ containers.
Environment variables are key-value pairs that are part of the worker’s runtime environment. They are used to configure applications and pass information into containers at runtime. This approach aligns with the Twelve-Factor App methodology, which recommends storing configuration in the environment.
Common uses for environment variables include:
- Setting database connection strings
- Configuring API keys and secrets
- Specifying runtime modes (e.g., development, production)
- Adjusting application behavior without changing code
By using environment variables, you can easily manage different configurations across various deployment environments and keep sensitive information out of your codebase.
Secret Variables
Secret variables are shared among all workers within a service. In addition to regular environment variables, Ptah.sh supports secret variables. These are similar to environment variables but offer enhanced security features:
- Storage: Secret variables are stored solely on the Docker Swarm cluster.
- Encryption: The data is encrypted with a Docker Swarm cluster’s key while it is stored in the task execution queue.
- Access: Secrets are only decrypted and made available to the container at runtime.
Secret variables are ideal for storing sensitive information such as:
- API keys
- Database passwords
- OAuth tokens
- SSL certificates
To use secret variables in Ptah.sh:
- When configuring your service, locate the “Secret Variables” section in the worker settings.
- Add your secret key-value pairs.
- Reference these secrets in your application code as you would with regular environment variables.
By utilizing secret variables, you can ensure that sensitive data is kept secure and separate from your regular configuration, reducing the risk of accidental exposure or unauthorized access.
Config Files
Config files are shared among all workers within a service. Each service may have a list of config files that are mounted to its workers’ containers. Users can specify:
- Path: The location where the file should be mounted in the container
- File Contents: The actual content of the configuration file
This allows for easy management and deployment of configuration files alongside your services.
Examples
-
Nginx configuration:
- Path:
/etc/nginx/nginx.conf
- File Contents:
- Path:
-
PHP configuration:
- Path:
/usr/local/etc/php/php.ini
- File Contents:
- Path:
-
Application-specific configuration:
- Path:
/app/config.json
- File Contents:
- Path:
These examples demonstrate how you can use config files to manage various types of configurations, from web server settings to application-specific options, directly within your Ptah.sh service definition.
Secret Files
Secret files are shared among all workers within a service. In addition to config files, Ptah.sh supports secret files. These are similar to config files but offer enhanced security features:
- Storage: Secret files are stored solely on the Docker Swarm cluster.
- Encryption: The file contents are encrypted with a Docker Swarm cluster’s key while stored in the task execution queue.
- Access: Secrets are only decrypted and made available to the container at runtime.
- Confidentiality: The contents of secret files cannot be read by the Ptah.sh panel.
Secret files are ideal for storing sensitive information that needs to be mounted as a file in the container, such as:
- SSL certificates and private keys
- OAuth client secrets
- API configuration files with sensitive data
- Database connection files
To use secret files in Ptah.sh:
- When configuring your service, locate the “Secret Files” section in the worker settings.
- Specify the path where the file should be mounted in the container.
- Provide the contents of the secret file.
Examples
-
SSL Certificate:
- Path:
/etc/ssl/private/example.com.pem
- File Contents: (The actual SSL certificate and private key)
- Path:
-
Database Connection File:
- Path:
/app/db-credentials.json
- File Contents:
- Path:
-
OAuth Client Secret:
- Path:
/app/oauth_secret.txt
- File Contents: (The actual OAuth client secret)
- Path:
-
API Configuration:
- Path:
/app/api_config.yml
- File Contents:
- Path:
By utilizing secret files, you can securely manage sensitive data that needs to be mounted as files in your containers, ensuring that this information remains encrypted and inaccessible to the Ptah.sh panel or unauthorized users.
Expose as HTTP(s)
Each worker can be configured for public access over the internet using either direct port publishing or Caddy endpoints.
You can use Caddy endpoints to map services to HTTP and HTTPS. When configuring a Caddy endpoint, you need to provide the following information:
- Container Protocol: Currently, either HTTP or FCGI
- Container Port: The port your service is listening on inside the container
- Published Port: Either HTTP (80) or HTTPS (443)
- Domain: The domain name for the service
- Path: The URL path to listen on, which can include placeholders (e.g.,
/*
listens at any request path starting from the root)
This configuration allows for flexible and powerful routing of HTTP/HTTPS traffic to your services, including support for multiple domains and path-based routing.
Redirect Rules
Redirect Rules allow users to specify URL redirects. When configuring a redirect, you need to provide:
- Domain From: The source domain
- Domain To: The destination domain
- Status: The HTTP redirect status code (301, 302, 307, or 308)
- Path From: The source path (supports regular expressions)
- Path To: The destination path
Redirects are useful for scenarios such as domain changes, HTTP to HTTPS redirects, or URL structure changes.
Examples
-
Blog migration:
- Domain From:
old-domain.com
- Domain To:
new-domain.com
- Status: 301
- Path From:
/blog/(.*)
- Path To:
/articles/$1
This would permanently redirect all blog posts from the old domain to the articles section on the new domain.
- Domain From:
-
www to non-www redirect:
- Domain From:
www.example.com
- Domain To:
example.com
- Status: 301
- Path From:
/(.*)
- Path To:
/$1
This would permanently redirect all requests from the www subdomain to the root domain, maintaining the same path and query parameters.
- Domain From:
These examples demonstrate how Redirect Rules can be used to manage common URL redirection scenarios in Ptah.sh.
Rewrite Rules
Rewrite Rules allow users to modify URLs internally without changing what the user sees in their browser. When configuring a rewrite, you need to provide:
- Path From: The source path (supports regular expressions)
- Path To: The destination path
Rewrites are useful for implementing clean URLs, content organization, or URL structures that don’t directly map to your file system.
Examples
-
Clean URLs:
- Path From:
/products/(.*)/(.*)
- Path To:
/products.php?category=$1&item=$2
This would internally rewrite a URL like
/products/electronics/smartphone
to/products.php?category=electronics&item=smartphone
, allowing for a cleaner URL structure.These powerful routing features in Ptah.sh enable you to create sophisticated URL handling schemes without modifying your application code, improving both SEO and user experience.
- Path From:
Expose as TCP/UDP
When publishing ports directly, users can specify two port numbers:
- The published port on the node (available from the internet)
- The target port on the container
This allows for flexible port mapping between the host and the container, enabling you to expose services on specific ports while potentially using different internal port numbers.
1-Click Apps
1-Click Apps are preconfigured applications that can be quickly deployed to your server node. They provide a streamlined way to set up common services or processes without the need for manual configuration.
To use a 1-Click App when creating a service:
- Navigate to the service creation page.
- Select the desired 1-Click App from the available templates.
- Click “Use template” to apply the 1-Click App configuration to your new service.
We recommend using 1-Click Apps to deploy any service that is not part of your core system, as they come preconfigured with best practices and can save significant setup time.
For more detailed information on 1-Click Apps, including how to use them and their benefits, see the 1-Click Apps page.
You can browse all available 1-Click Apps in the Marketplace page.