An easy way to deploy Docker containers to your VPS using Ptah.sh

Bohdan Shulha
6 min readAug 15, 2024

--

Ptah.sh Slogan

For a quite long time you didn’t hear of me on Medium. Can you guess what happened?

Right! I’ve been working on a new SaaS!

Creation Story

Back in 2020, my friend Andrii approached me with a proposal to start a new small startup — an esports statistics website. Knowing that Andrii is a master of strategic thinking, I had no doubt that the project wouldn’t take off, so I immediately agreed. We met at a restaurant where I, having watched too many Silicon Valley movies, drew the initial service architecture on a napkin. Overall, this says a lot about what we knew about the IT business in general at that time. :)

Throughout the history of running this website, I migrated between different clouds several times — from Heroku, through AWS, to DigitalOcean. Sometimes the reason was performance, sometimes cost, sometimes both.

Tired of constantly configuring everything and influenced by the #buildinpublic community on X (formerly Twitter), I decided to formalize my knowledge and skills in the form of a convenient (at least for me) service that would help me launch new subsystems for this project more easily.

As a result, we managed to save 82% of the monthly budget ($3.5k yearly) that we were using only for servers and databases.

TLDR; If you like to see all-in-one video introduction, here’s the recording on YouTube!

Ptah.sh Architecture

Ptah.sh is a Fair Source software consisting of two main components:

  1. Server Agent: Installed on a VPS, this agent interacts with the system and the running Docker Daemon. It executes predefined commands for creating, updating, and running services and backups.
  2. Web-based UI: This interface allows users to configure services, access points, and schedule periodic tasks.

Key Features and Benefits:

  • Flexible Deployment: Deploy services in any environment, whether it’s on virtual or physical machines from any provider, or even in a home office setup.
  • Enhanced Security: The virtual machine can have all ports closed while still allowing service deployment, ideal for intranet infrastructure.
  • Open Source Advantage: The open-source nature of the software theoretically ensures quick resolution of critical vulnerabilities.
  • Fair Source Model: This allows hosting the service on your own hardware, giving you full control over your entire infrastructure.
  • Docker Swarm Integration: As a key system element, Docker Swarm ensures service isolation within their networks, enables multi-node clustering, and enhances overall system reliability.
  • Vendor Lock-in Prevention: All configurations are stored on the Docker Swarm cluster. This means you can discontinue the service at any time while retaining the ability to perform deployments, ensuring your site, application, or API won’t suddenly stop functioning.

This architecture provides a robust, flexible, and secure solution for managing and deploying Docker containers across various environments.

Deploying Services

Now that you understand how the system works behind the scenes, it’s time to try deploying something and see the service in action.

To get started, you’ll need:

  • A fresh VPS (Virtual Private Server) running Ubuntu operating system.
  • An account on ptah.sh.
  • An internet connection. ;)

With these prerequisites in place, you’re ready to experience firsthand how Ptah.sh simplifies the process of deploying and managing services. The following steps will guide you through setting up your first deployment using this intuitive platform.

Step 1 — Installing Docker and the Agent

To deploy Docker containers, you need to install both Docker and the Ptah.sh agent. Fortunately, this process is straightforward: the service will generate a bash command for you, so all you need is the common skill of copy-pasting. :)

Once you run the script in your server’s console, you’ll have:

  • The latest version of Docker Engine installed.
  • The latest version of the Ptah.sh Agent installed.
  • A systemd configuration for automatic (re)starting of the Agent.

This simple setup process ensures that your server is fully prepared to work with Ptah.sh, allowing you to focus on deploying and managing your services rather than dealing with complex installation procedures.

Step 2 — Initializing the Docker Swarm Cluster

Once you’ve installed the agent and your server card on the dashboard has changed from a red “Offline” to a green “Online” status, you can proceed to initialize the Docker Swarm cluster. This cluster is where your services will actually run.

Among the necessary parameters is the Advertisement Address. This is important if you plan to create a multi-server cluster in the future. Here’s how to choose:

  • If all your servers will be within the same network of your provider, select the internal address.
  • If your requirements include having multiple geographic zones (different providers, availability zones, etc.), choose the external address.

This step is crucial for setting up a flexible and scalable infrastructure that can grow with your needs. The choice of Advertisement Address will impact how your Swarm nodes communicate, so consider your current setup and future plans when making this decision.

Step 3 — Deploying a Service

For this test, we’ll deploy a simple Docker Image — nginxdemos/hello. This image contains an nginx server that will return a dynamic page to the browser with basic information about the HTTP request: address, hostname (container), date, and time of request processing.

Key parameters you’ll need to specify:

  1. Service name
  2. Docker Image to use for the container
  3. HTTP Endpoint through which the launched service can be accessed

By default, Ptah.sh runs Caddy, which handles all external HTTP requests and automates certificate acquisition through Let’s Encrypt.

In addition to these basic settings, you can configure:

  • Environment variables (both public and secret)
  • Configuration files (also public and secret)
  • Docker Volumes (for persistent storage on disk)
  • Backups (using custom-defined commands and automated Volume backups)
  • Additional processes (workers for heavy tasks)
  • Extra Docker Services that function similarly to Sidecar Containers in Kubernetes (e.g., for pgbouncer/pgpool)

This flexibility allows you to set up complex, multi-component services while keeping the deployment process straightforward and manageable.

Here’s the English translation and slight rephrasing:

Step 4 — Verifying Service Functionality

Once the service deployment is complete, you can view the results in your favorite browser.

In the previous step, we specified that the service would run on localhost and handle all requests starting with /nginx-demos/. Additionally, we indicated that it should listen for requests on the HTTPS port, so Caddy will configure the corresponding endpoint.

The full link for testing is: https://localhost/nginx-demos/dou-demo

After passing through a cautionary screen regarding certificate integrity (since this is localhost), you should see the following screen:

An nginx server running on the ptah.sh infrastrucutre

This step confirms that your service is up and running correctly, demonstrating the ease of deployment and immediate functionality provided by Ptah.sh.

As you can see, we’ve bypassed many configuration-related issues thanks to the opinionated approach of the service. This streamlined process demonstrates how ptah.sh simplifies deployment, allowing you to focus on your application rather than getting bogged down in complex configuration details.

The opinionated nature of ptah.sh means it makes certain decisions for you, based on best practices and common use cases. This approach significantly reduces the time and effort required to get a service up and running, while still providing flexibility for more advanced configurations when needed.

By completing this process, you’ve experienced firsthand how ptah.sh can make Docker deployment more accessible and efficient, even for those who might not be experts in server configuration or Docker Swarm orchestration.

What’s Next?

As a conclusion, I invite you to personally try deploying your own service using ptah.sh, and the promo code MEDIUM will help you save if you decide to stay longer.

If you want to follow the development process, I invite you to join the following networks:

And, be sure to join the voting on Product Hunt on September 1st!

Ptah.sh on Product Hunt

What are the plans?

In general, you can familiarize yourself with the plans on GitHub — I try to group tickets into milestones.

However, if we look from a bird’s eye view, here’s what I want to do next:

  • Real-time status updates for tasks performed by the agent (currently you need to press F5).
  • Implement the ability to configure log export to systemd and AWS-compatible storages.
  • Create 1-Click templates for popular applications (databases like PostgreSQL + PGPool, web services like WordPress, and others).

Thank you! :)

--

--