Use Cloudflared Docker to Map Your Sub Domain to Application in Free PaaS (Codesandbox.io)

This blog post shows you how to deploy Cloudflare docker into PaaS to map your sub domain to the apps in it. 

There is any way to map your domain to Codesandbox PaaS, which is to use vercel, as shown from github project: https://github.com/k0baya/reserve-vercel/.

Codesandbox Free Tier

Usage

  • Up to 40 hours worth of VM credits per month
  • VMs up to 4 vCPUs + 8 GiB RAM
  • 5 private Sandboxes
  • Unlimited public Sandboxes
  • Unlimited Devboxes and repositories
  • 5 members
Features

  • Private Sandboxes, Devboxes & repos
  • 100 Codeium AI code completions
  • Live collaboration
  • VS Code extension
  • Instant environment resume
  • Instant environment share

Usage status:

Each Nano VM will cost you 10 credits / hour:

Every month, you will get 400 credits to use, which is 40 hours for a Nano vm.

Nano vm has 2vCPUs, 4GB RAM, 20GB Disk

Steps to Create a Cloudflared Docker with APP

1 Create your workspace box, either devbox or sandbox

2 Create Docker

You will be only able to select Devbox for this type of template:

3 Modify tasks.json file under workspace/.codesandbox

{
  // These tasks will run in order when initializing your CodeSandbox project.
  "setupTasks": [
    {
      "name": "Deploy",
      "command": "cd /project/workspace/.devcontainer/ && docker compose up -d"
    }
  ],

  // These tasks can be run from CodeSandbox. Running one will open a log in the app.
  "tasks": {
    "cloudflare": {
      "name": "cloudflare",
      "command": "cloudflare",
      "runAtStart": true
    }
  }
}

4 Create docker-compose.yaml file under workspace / .devcontainer

version: "2"
services:
  qinglong:
    image: whyour/qinglong:latest
    volumes:
      - /project/sandbox/ql/data:/ql/data
    ports:
      - "0.0.0.0:5700:5700"
    environment:
      QlBaseUrl: "/"
    restart: always

  cloudflared:
    restart: always
    network_mode: host
    environment:
      - tz=america/new_york
    command: tunnel --edge-ip-version auto --protocol quic --heartbeat-interval 10s run --token eyJhIjoiNDIwOTFiYzM3NjMxNmJjZDA5YWViM2VjYmYyNDM2ZTMiLCJ0IjoiYjQ0NWI1NmMtMTQzMS00NjJiLWFjNGMtMzMzNmRjY2RjNmU4IiwicyI6Ik1HRXlOMlZrT1RBdFlqWTJNaTAwTW1FekxUZ3dNR0l0WVRsbVpqZG1ZbUU0TXpjMSJ91
    container_name: cloudflared
    image: cloudflare/cloudflared:latest


Once you pressed ctrl+s to save dockercompose.yaml file, it will ask you to rebuild & restart the deccontainers. 

Manual Running the docker if task does not work:

Open a shared Terminals

Run following commands: 

  • cd /project/workspace/.devcontainer/ && docker compose up -d

Cloudflare 

 

1. Create a tunnel in Zero Trust / Networks / Tunnels

2. Make sure you created your Public hostname to map to your Codesandbox app created in previous step:

3. Test the public domain

Other Settings

 Check System usage

Port forwarded Address

Uptime Kuma

Other apps

 

Uptime-kuma
version: "3.8"
services:
  uptime-kuma:
    image: louislam/uptime-kuma:1
    container_name: uptime-kuma
    volumes:
      - /project/sandbox/uptimekuma:/app/data
    ports:
      - "5700:3001" # <Host Port>:<Container Port>
    restart: always

  cloudflared:
    restart: always
    network_mode: host
    environment:
      - tz=america/new_york
    command: tunnel --edge-ip-version auto --protocol quic --heartbeat-interval 10s run --token eyJhIjoiNDIwOTFiYzM3NjMxNmJjZDA5YWViM2VjYmYyNDM2ZTMiLCJ0IjoiYjQ0NWI1NmMtMTQzMS00NjJiLWFjNGMtMzMzNmRjY2RjNmU4IiwicyI6Ik1HRXlOMlZrT1RBdFlqWTJNaTAwTW1FekxUZ3dNR0l0WVRsbVpqZG1ZbUU0TXpjMSJ91
    container_name: cloudflared
    image: cloudflare/cloudflared:latest

Multiple dockers deploy together:

version: "3.8"
services:
  uptime-kuma:
    image: louislam/uptime-kuma:1
    container_name: uptime-kuma
    volumes:
      - /project/sandbox/uptimekuma:/app/data
    ports:
      - "5800:3001" # <Host Port>:<Container Port>
    restart: always

  qinglong:
    image: whyour/qinglong:latest
    volumes:
      - /project/sandbox/ql/data:/ql/data
    ports:
      - "5700:5700"
    environment:
      QlBaseUrl: "/"
    restart: always

  cloudflared:
    restart: always
    network_mode: host
    environment:
      - tz=america/new_york
    command: tunnel --edge-ip-version auto --protocol quic --heartbeat-interval 10s run --token eyJhIjoiNDIwOTFiYzM3NjMxNmJjZDA5YWViM2VjYmYyNDM2ZTMiLCJ0IjoiYjQ0NWI1NmMtMTQzMS00NjJiLWFjNGMtMzMzNmRjY2RjNmU4IiwicyI6Ik1HRXlOMlZrT1RBdFlqWTJNaTAwTW1FekxUZ3dNR0l0WVRsbVpqZG1ZbUU0TXpjMSJ91
    container_name: cloudflared
    image: cloudflare/cloudflared:latest

Keep System Active

Online Monitoring Codesandbox url such as https://t2s3qd-5700.csb.app this url:

cron-job.org

UptimeRobot

Or, create your own monitor site:

Uptime-Kuma

Videos

 

References

 

版权声明:
作者:Mr李
链接:https://www.techfm.club/p/169719.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>