Skip to main content

Quick installation of Python Apps

First, make sure you have the following tools installed:

  • Docker

Step 1: Write your Python program

  • Create a file named in your project directory and add the following code:

    from flask import Flask, render_template
    import mysql.connector

    app = Flask(__name__)

    def get_data_from_database():
    cnx = mysql.connector.connect(

    cursor = cnx.cursor()
    cursor.execute("SELECT * FROM test")
    data = cursor.fetchall()

    return data

    def index():
    data = get_data_from_database()
    return render_template('index.html', data=data)

    if __name__ == '__main__':'', debug=True)

  • Create a file named requirements.txt in the directory to list the dependencies required by the application.

  • Create a folder named templates in your project directory and create a file named index.html inside it. Add the following content to index.html:

    <!doctype html>
    <html lang="en">
    <meta charset="utf-8">
    <title>Data from MySQL</title>
    <h1>Data from MySQL</h1>
    {% for row in data %}
    <td>{{ row[0] }}</td>
    <td>{{ row[1] }}</td>
    <td>{{ row[2] }}</td>
    {% endfor %}

    Replace `Column1`, `Column2`, and `Column3` with the actual column names you want to display.

Step 2: Create a Docker image

  • Create a file named Dockerfile in the root directory of the project. This file will contain the instructions needed to build the Docker image. Here is a simple example Dockerfile:

    FROM python:3.8

    WORKDIR /app

    COPY requirements.txt .

    RUN pip install --no-cache-dir -r requirements.txt

    COPY . .

    EXPOSE 5000

    CMD ["python", ""]

Step 3: Build the Docker image

  • Run the following command in the directory containing the Dockerfile to build the Docker image:

    docker build -t python-demo .

Step 4: Push the Docker image

  • Push the created Docker image to a Docker repository, such as Docker Hub or a private repository. Assuming that you have logged in to the Docker repository, use the following command to push the image:

    • First, tag the Docker image. Before pushing the image, you need to add a tag to it so that Docker knows where to push it. Run the following command to add a tag to the image:

      docker tag your-image-name your-dockerhub-username/your-repo-name:your-tag

      Replace your-image-name with your local image name, your-dockerhub-username with your Docker Hub username, your-repo-name with the name of the repository you want to create on Docker Hub, and your-tag with the tag you set for the image (e.g. latest).

      For example:

      docker tag python-demo damager6666/python-demo:v1
    • Next, push the Docker image. Use the following command to push the image to Docker Hub:

      docker push your-dockerhub-username/your-repo-name:your-tag

      Replace your-dockerhub-username, your-repo-name, and your-tag with the actual values. For example:

      docker push damager6666/python-demo:v1

Step 5: Log in to Sealos

Step 6: Open the "Database" application

Step 7: Create a database

  • Click "Create Database"

  • Basic Configuration:
    • Cluster Type: mysql
    • Cluster Name: demo-db
    • CPU (Recommended): 1 Core
    • Memory (Recommended): 1 G
    • Number of Instances: 1
    • Storage Capacity: 1 Gi
  • Click "Deploy Cluster"

Step 8: Configure the database

  • Click "Connect to the Database" and execute the following SQL statements:

    • Create the test_db database

      create database test_db;
    • Create the test table

      CREATE TABLE `name_info` (
      `id` int(11) NOT NULL,
      `name` varchar(12) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
      PRIMARY KEY (`id`)
    • Insert data

      insert into test values (1,'Sealos');

Step 9: Open the "App Management" application

Step 10: Create a new app

  • In "App Management", click "New App" to create a new app.

Step 11: App deployment

  • Basic Configuration:
    • Application Name (Customized): python-demo
    • Image Name: damager6666/python-demo:v1
    • CPU (Recommended): 1 Core
    • Memory (Recommended): 1 G
  • Deployment Mode:
    • Number of Instances (Customized): 1

  • Network Configuration:
    • Container Exposed Port: 5000
    • External Access: Enabled

Step 12: Deploy the app

Step 13: Access the app

  • Click "App Management" to check when the STATUS of the app changes from "Pending" to "Running", indicating that the app has been successfully launched.
  • When the STATUS is Running, you can directly access the external network address.

  • Enter the external network address in the browser to access the data that was just stored in MySQL, indicating that the program has been successfully deployed on Sealos.