轩辕镜像 官方专业版
轩辕镜像
专业版
轩辕镜像 官方专业版
轩辕镜像
专业版
首页个人中心搜索镜像
交易
充值流量¥7起我的订单
文档
工具
提交工单页面收录
civis-services-flask

civisanalytics/civis-services-flask

civisanalytics

Example Flask app hosted in Civis

下载次数: 0状态:社区镜像维护者:civisanalytics仓库类型:镜像最近更新:11 个月前
让 AI 帮你使用轩辕镜像? · 展开查看说明 · 点击收起说明

如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。

只需在 AI 对话中先发送下面这句话即可:

请先完整阅读并严格遵守以下文档中的全部规则与要求:

https://xuanyuan.cloud/agents.md

在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。

查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。

镜像简介
下载命令
镜像标签列表与下载命令
轩辕镜像,让镜像更快,让人生更轻。
点击查看

Civis Services Flask Demo

This repository shows you how to host a web application in Civis Platform. The example provided here is a simple Flask app. This app queries the service for data in JSON format to display on the page.

Requirements

To host your modified service on Civis Platform, you will need a Github account. See this article in the Civis Help Center if you have not yet connected your Github account to Civis.

To make changes to and run this application, you will need git and Docker installed on your machine. Civis uses Docker to host web applications, so using Docker locally is the most reliable way to develop and troubleshoot your application. You can follow the instructions https://docs.docker.com/get-docker/ to install Docker on your machine.

Getting Started

Testing out the service in Civis Platform

First, let's run this Github repo (the one you are reading right now) as a service in Civis.

  1. Go to [***] to create a new Service.
    1. Find the "Git Connection" fields.
      1. Repository: https://github.com/civisanalytics/civis-services-flask.git
      2. Branch: main
    2. Find the "Docker" fields.
      1. Image name: civisanalytics/civis-services-flask
    3. Leave all other fields blank or with their default values.
  2. Click Start Deployment to run the service.
  3. Keep track of this service so you can find it later. You can bookmark it, give it a distinctive name so you can find it in the Platform search bar, or add it to a project.

Once the service has started up, you should see a "Your service is running!" message in the preview window. You can also view the logs for the service by clicking Deployment History.

Click Stop Deployment to shut down the service and stop using compute resources. If you forget to shut down the service, it will sleep automatically after one hour of inactivity.

Running the service locally

Next, let's run the service on your own machine.

  1. Clone this git repo.
  2. Start Docker on your machine if it is not already running.
  3. From the directory you cloned into, run docker-compose up --build -V.
  4. See your web app locally at http://localhost:3838/ in your web browser. You should see the same application you saw in Civis, though with slightly different information (we'll fix that later).
  5. Use CTRL-C to stop the web server.

Every time you make a change to the code, you should stop docker-compose and start it again. Subsequent runs will start up much faster.

Customizing the Environment

Add a local API key

You might have noticed one or two differences between the applications running in Civis and locally. Applications running in Civis have an API key automatically provided in the CIVIS_API_KEY environment variable. This Flask app uses that key to retrieve the username of the owner of the service. If the last item in the response has name: null then you don't have this variable set locally. This is normal.

We recommend setting this value in a .env file. docker-compose will automatically read this file and it will be ignored by git.

  1. Generate a Civis API key by following the instructions here.
  2. Create a .env file in the same directory as this README.
  3. Add a line to the .env file with:
    CIVIS_API_KEY=<the API key you just generated>
    
  4. Run the service locally (same steps as above)

You should now see your Civis username on the page.

Choose your favorite fruit

The API response from the service includes an is_favorite attribute for each of the fruits, but the value should be false for every fruit. The app can be configured with a favorite fruit using a different environment variable.

First, we'll set this variable locally.

  1. Add a line to the .env file with:
    FLASK_DEMO_FAVORITE_FRUIT_PASSWORD=<your choice of: Strawberry, Watermelon, Grapefruit, or your username>
    
  2. Restart the local service (CTRL-C to stop it and then docker-compose up --build -V to restart it)

You should now see that the fruit you selected is marked as a favorite!

Next, we'll configure the service running in Civis to receive this environment variable. To do this, we will first create a Civis Credential and then attach that credential to the service.

  1. Go to [***]
    1. Click Create Credential
      1. Name: Flask Demo Favorite Fruit
      2. Type: Custom
      3. Username: fruit (for this example the username will not be used)
      4. For the password, enter the same value you choose for your favorite fruit locally: Strawberry, Watermelon, etc.
      5. Leave all other fields blank or with their default values.
      6. Click Save
  2. Go to the service you created previously. If you can't find it, you can go to [***] and find it in the list of all services you have access to.
    1. Find the "Security and Access" fields.
      1. Click in the "Credentials" box and select the Flask Demo Favorite Fruit credential. This will make the username and password of the credential available to the service through environment variables.
    2. Click Start Deployment to start the service. If the service is still running from the last time you started it, click Stop Deployment and wait for the page to update, then click Start Deployment to restart it.

You should again see that the fruit you selected is marked as a favorite! If not, try refreshing the page to make sure you are not looking at an old version of the service.

Modifying the code

You should now be comfortable running the service locally and in Civis Platform. To make further changes, fork this Github repo into your own account and create a new service in Civis connected to your forked repo. As you push changes to Github, you will see them reflected in the service when you stop and restart it.

If you want to host multiple applications in a single repository, you can set the Git Path Directory on the service to select between them. The entrypoint of this docker image will cd to that directory and atte*** to run start_service.sh. For other custom configurations, you may want to build a custom docker image.

Additional Notes

Updating your service

Instead of clicking Stop Deployment, you could instead click on Update Deployment. This will redeploy your service with no downtime, i.e., your old application will still be available while your new version is starting up. This is a great option for your production applications, but during development it can be unclear whether you are looking at an old or new version of the app. We recommend stopping and starting the service while testing out changes.

Adding packages

If you would like to upgrade your packages or install new packages, please add to the requirements.txt file at the root of this repo. You can also modify the start_service.sh script if you need to install libraries or more complex dependencies.

The Civis API key

In Platform, the CIVIS_API_KEY variable belongs to the user who owns the service, not the user making the request to the service. Be careful about making requests on behalf of users, as this might pose a security risk.

Front end changes

This example application does not atte*** to set up a fully featured front end. It uses a simple HTML and Javascript file. The frontend lives in the dist folder. The index.html file uses main.js to call the /fruits endpoint and update the page.

You can use React, Angular, or any other Javascript framework in your service. Just make sure that your root API endpoint (/) returns the initial landing page for your app. If not, Platform will *** your app to be down and continuously atte*** to restart it.

NOTE: Browsers will often cache HTML and Javascript files by name. Therefore, we recommend having the Javascript file(s) named using a commit hash or similar to prevent caching.

Accessing your service from inside Civis Platform

You can access your service's API easily using a Civis API key. All applications running in Civis are automatically provided with an API key, so you can use this key to access a running service without needing an additional authentication token. To provide or revoke access to the service, click Share on the service page to modify permissions.

In the example below, we will hit the API of a Platform service from a Platform notebook. Make sure your service is running before trying out this example. In production code, you would want to catch this sort of error, deal with timeouts, etc.

  1. Go to [***] and click Start Server to start up a new Jupyter notebook.

  2. Direct access to the service expires after five minutes. We recommend using the cachetools package to re-authenticate with the service every 2 minutes. Run the following code in your notebook:

    !pip install cachetools
    
  3. In the next cell, store your service ID in a variable so it can be reused:

    SERVICE_ID = <your service ID>
    
  4. Now add code for making an authenticated request to the service:

    import requests
    import cachetools.func
    
    @cachetools.func.ttl_cache(ttl=120)
    def _service_session(service_id):
        session = requests.Session()
        service = client.services.get(service_id)
        auth_url = service['current_deployment']['displayUrl']
        base_url = service['current_url']
        session.get(auth_url)
        return [session, base_url]
    
    def service_request(service_id, endpoint):
        session, base_url = _service_session(service_id)
        resp = session.get(base_url + endpoint)
        return resp
    
  5. You should now be able to access the API for the service:

    service_request(SERVICE_ID, "/api/health").text
    

    should return the result:

    'The ID of this service is: ...'
    

    The fruits API endpoint:

    service_request(SERVICE_ID, "/api/fruits/").json()
    

    should match the result shown on the service page.

Accessing your service from outside of Civis Platform

You can also access your service's API from outside of Platform. This is not recommended, but sometimes necessary to allow access from other systems.

In order to do this, you must generate a service token for your service. See [***] for more information. You must be signed into Civis to view that documentation. You can revoke the service token to revoke access to the service.

镜像拉取方式

您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

轩辕镜像加速拉取命令点我查看更多 civis-services-flask 镜像标签

docker pull docker.xuanyuan.run/civisanalytics/civis-services-flask:<标签>

使用方法:

  • 登录认证方式
  • 免认证方式

DockerHub 原生拉取命令

docker pull civisanalytics/civis-services-flask:<标签>

轩辕镜像配置手册

按平台快速找到配置文档

一键安装

一键安装 Docker

Linux Docker 一键安装

AI

用 AI 使用轩辕镜像

agents.md · AI 对话 · 提示词

Docker

登录仓库拉取

登录认证 · 私有仓库

专属域名拉取

免登录 · 高速拉取

Linux

Docker 镜像配置

Windows / Mac

Docker Desktop 配置

MacOS OrbStack

OrbStack 容器

Apple Container

macOS 原生容器

Docker Compose

Compose 项目配置

NAS

群晖

Synology 配置

飞牛

fnOS 镜像配置

绿联

绿联 NAS

威联通

QNAP 配置

极空间

极空间 NAS

Unraid

Unraid NAS

企业仓库

其他仓库

ghcr · Quay · nvcr

Harbor 镜像源

Proxy Repository 对接

Portainer 镜像源

Registries 配置

Nexus 镜像源

Docker Proxy 缓存

开发工具

Dev Containers

VS Code 开发容器

Podman

Podman 配置指南

Singularity / Apptainer

HPC 科学计算容器

Kubernetes

K8s Containerd

Kubernetes · Containerd

K3s

轻量级集群

面板 / 网络

爱快路由

iKuai 镜像加速

宝塔面板

一键配置镜像源

需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单

镜像拉取常见问题

功能

版本功能对比

功能对比 · 版本选择

支持的镜像仓库

Docker Hub · GCR · GHCR

新手拉取配置

登录 · 专属域名 · 配置

docker search 限制

专属域名 · Hub 搜索

不支持 push

仅支持 pull · 不支持

拉取速度原因

带宽 · 缓存 · 冷热镜像

错误码

402 与流量用尽

402 · 流量包 · 充值

401 认证失败

401 · docker login

manifest unknown

标签错误 · 镜像不存在

410 Gone 排查

410 · Docker 升级

429 限流

免费版 · 专业版 · 企业版 · 请求频率

其他报错

DNS 超时

DNS 解析 · 网络超时

TLS 证书失败

no matching manifest(架构)

账号

失败是否计费

manifest · blob · 计费

申请开发票(企业 / 个人)

企业 · 个人 · 工单

修改登录密码

网站 · 仓库 · 重置

注销账户

工单 · 数据 · 注销

原理

mirrors 不生效

daemon.json · 重启

去掉域名前缀

docker tag · 重命名

指定架构拉取

ARM64 · AMD64 · 多架构

latest 与「最新」

digest · 版本号 · 标签

查看全部问题→

用户好评

来自真实用户的反馈,见证轩辕镜像的优质服务

用户头像

oldzhang

运维工程师

Linux服务器

5

"Docker访问体验非常流畅,大镜像也能快速完成下载。"

轩辕镜像
镜像详情
...
civisanalytics/civis-services-flask
教程轩辕镜像功能与使用教程
定价查看流量套餐与价格
热门查看热门 Docker 镜像推荐
博客Docker 镜像公告与技术博客
专业版 · 高速稳定拉取镜像
高速镜像下载·在线技术支持·99.95% SLA 保障·付费会员免广告
50GB 仅 ¥7/年
专业版 · 高速稳定拉取镜像
50GB 仅 ¥7/年
高速镜像下载·在线技术支持·99.95% SLA 保障·付费会员免广告
用户协议·隐私政策·增值电信业务经营许可证:浙B2-20261007·©2024-2026 源码跳动©2024-2026 杭州源码跳动科技有限公司·商务合作:点击复制邮箱

更多 civis-services-flask 镜像推荐

demisto/flask-nginx logo

demisto/flask-nginx

demisto
暂无描述
100万+ 次下载
19 天前更新
jetbrains/ide-services logo

jetbrains/ide-services

jetbrains
JetBrains IDE Services服务器官方镜像。
4 次收藏1万+ 次下载
9 天前更新
circleci/hello-flask-nginx logo

circleci/hello-flask-nginx

circleci
此镜像仅供内部使用
5万+ 次下载
10 年前更新
jetbrains/ide-services-helm logo

jetbrains/ide-services-helm

jetbrains
JetBrains IDE Services 官方 Helm 图表,用于在 Kubernetes 集群中部署和管理 IDE Services 实例。
1 次收藏7千+ 次下载
9 天前更新
appdynamics/ad-air-java-services logo

appdynamics/ad-air-java-services

appdynamics
暂无描述
4.5千+ 次下载
5 年前更新
appdynamics/ad-air-mock-services logo

appdynamics/ad-air-mock-services

appdynamics
暂无描述
3.1千+ 次下载
5 年前更新

查看更多 civis-services-flask 相关镜像