docker2saas
简体中文
Screenshots
for members ( who subscribe the plan )
for admin
⚠️ This document was translated into English by deepl and can be improved by PR
An open source tool that lets you create SaaS websites from images in as
little as 10 minutes.
Docker2SaaS is a tool that enables multi-tenancy through virtualization
technology (calling cloud platform api ) with tenant management and subscription
managment. It helps web application and service developers to quickly build
websites for sale or subscription. All you need to do is make an image of your application and
then set up and configure a Docker2SaaS site to start selling your application as a service.
When a user’s subscription is successful, it automatically creates a VPS from
the image as configured; when the user cancels the subscription and it expires,
it automatically deletes the VPS. Users can login to the site and see their
subscription, host IP information, and other details. Additional extensions can be
added.
The diagram below shows how Docker2SaaS interacts between:
End Users
Payment provider: Stripe
Cloud service provider: DigitalOcean.
Target Users of Docker2SaaS
Docker2SaaS is aimed at developers of cloud applications, providing them with a
solution to quickly monetize their applications.
Let’s say you develop a nice little web app and open source it to Github.
Developers easily build it and use it on their own, but as the app becomes more
popular, so do non-technical users. But even if they have already made a docker
file, it is still difficult for them.
At this point you may want to provide a cloud hosting version. On the one hand,
you can solve the details of the build for non-technical users, and on the other
hand, hosting can bring some profit, so you can get a financial return.
However, this can create an additional amount of development, and it doesn’t
seem wise to spend weeks on development before you know if cloud hosting will be
popular.
Fortunately, the open source Docker2SaaS solves this problem, and it only takes
ten minutes to configure and you can get a simple and usable cloud hosting sales
site. It’s immediately ready for early sales, and you can modify the source code
to add more business-related features as user demand increases.
Of course, it can also be used to build a third-party sales site under the
license of a cloud application developer. But overall, Docker2SaaS is designed
for developers and does not take into account the experience of non-technical
users, so if you don’t have a technical background, it’s better to use a
Docker2SaaS site that someone else has built rather than building it yourself.
PS: Docker2SaaS is built on Laravel, and while no knowledge is required for a
simple deployment, if you want to customize and add features, then you need to
have a little Laravel development knowledge.
Docker2Saas is licensed under the GPLv2 with an additional non-compete clause.
Docker2SaaS Guide
Steps
Digital Ocean configuration
Create a Digital Ocean image
We assume that you have already made a docker image of your application and can start it with the docker-compose command. Let’s use Ghost as an example to explain.
First we will create a droplet( Digital Ocean calls its VPS droplet ) on Digital Ocean and select docker on ubuntu
under marketplace
.
Then we log in to the newly created instance via SSH. Create our docker-compose.yaml file in the root directory (or somewhere else). Here we use the yaml provided by bitnami.
version: '2' services: mariadb: restart: always image: 'docker.io/bitnami/mariadb:10.3-debian-10' environment: - ALLOW_EMPTY_PASSWORD=yes - MARIADB_USER=bn_ghost - MARIADB_DATABASE=bitnami_ghost volumes: - 'mariadb_data:/bitnami' ghost: restart: always image: 'docker.io/bitnami/ghost:3-debian-10' environment: - MARIADB_HOST=mariadb - MARIADB_PORT_NUMBER=3306 - GHOST_DATABASE_USER=bn_ghost - GHOST_DATABASE_NAME=bitnami_ghost - ALLOW_EMPTY_PASSWORD=yes - GHOST_HOST=localhost - GHOST_EMAIL=guest@ftqq.com - GHOST_PASSWORD=admin ports: - '80:2368' volumes: - 'ghost_data:/bitnami' depends_on: - mariadb volumes: mariadb_data: driver: local ghost_data: driver: local
Note that we have added restart: always
to ensure that docker is started automatically when the image is started.
Once the file is created, go to droplet management and create a snapshot.
When you are done creating the snapshot, you can delete the droplet instance.
Go to the images page and look up the data-id of the snapshot in the source code corresponding to the snapshot entry you just created, this value (78661121 in the image) is the id of the snapshot. Record it, and we’ll use it later. (We’ll call this A1)
Creating a Digital Ocean Token
Next we will create a token so that we can manage droplet through the API. At the bottom of the left menu, select API.
In the Tokens/Keys tab, generate a new token with the read && write permissions selected.
Once generated, record it and you will need it later. (We’ll call it A2)
Stripe Configuration
The following are all described in Test mode.
Create a subscription
Go to the Stripe dashboard and create a product.
Note that in the Pricing section, select Recurring so that it will automatically renew. Fill in the rest of the fields as you wish.
After creating the product, go to the product details page, and you can see the API ID in the Pricing section, and record it. (We’ll write it down as B1)
You can create as many prices as you need, remember to record the price ids.
Get API key
In order to interact with the Stripe platform through the API, we also need the API key. click the Developer menu on the left, select API Keys, and record the publishable key and secret key on the right. (Note B2, B3)
Since then, the preparation is done.
Configuring Docker2SaaS
Site initialization
Download/clone the docker2saas source code to the environment where you want to run the sales site. This environment needs to be configured with PHP7.4+ and MySQL.
git clone https://gitlab.com/easychen/docker-2-saas.git --depth=1 docker2saas
Initialization of dependency packages:
cd docker2saas composer install
Rename .env.example
to .env
and run the command to generate APP_KEY
php artisan key:generate
Fill in other relevant information.
- APP_DEBUG : should be set to false after debugging is completed
- APP_URL : Website URL
- APP_LOGO_URL and APP_ICON_URL: Home page big picture and top menu icon
- DB_*: database related configuration
- STRIPE_KEY: the B2 in the previous article
- STRIPE_SECRET: B3 in the previous section
After creating the database docker2saas in MySQL, then run the command to initialize the database.
php artisan migrate
Start the development environment
php artisan serve --host=0.0.0.0 --port=8001
You can see the website by accessing port 8001 of the machine ip. Click register to register users and login automatically, the first registered user will become administrator automatically.
The administrator’s logic can be modified in app/Providers/AuthServiceProvider.php
.
Gate::define('saas-admin', function (User $user) { return $user->id == 1; });
Configure the site
Click on the settings tab to configure the basic information for the site, where DigitalOcean token
is A2 from above.
The DigitalOcean sshkey
is the public key you want to use to manage all droplets. if you don’t have one ready, you can create one by running the following command.
ssh-keygen -t rsa -f <name>
During the run, if you don’t want to set the passphrase, you can just press enter twice to set it to empty.
ssh-keygen -t rsa -f this
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
When this is done, .pub will be generated in the command directory, and its contents will be the sshkey we want to fill in the form.