{"slug":"tailscale-on-koyeb","title":"Tailscale on Koyeb","tags":["tailscale","setup"],"agent_summary":"Last validated: Jan 5, 2026","trigger_phrases":[],"runnable":false,"markdown":"\r\n# Tailscale on Koyeb\r\n\r\nLast validated: Jan 5, 2026\r\n\r\n[Koyeb](https://www.koyeb.com/) is a serverless platform for seamlessly deploying AI applications and databases on high-performance infrastructure, including CPUs, GPUs, and Accelerators around the world.\r\nYou can add Tailscale to a Koyeb application to let your Koyeb Services communicate with other devices and services in your tailnet.\r\n\r\n## [Step 1: Generate an auth key to authenticate your Service on Koyeb](https://tailscale.com/docs/install/cloud/koyeb\\#step-1-generate-an-auth-key-to-authenticate-your-service-on-koyeb)\r\n\r\nStart by [generating an auth key](https://tailscale.com/docs/features/access-control/auth-keys) to let your Koyeb service join your tailnet.\r\n\r\nOpen the [Keys](https://login.tailscale.com/admin/settings/keys) page of the admin console and select **Generate auth key**. It's best practice to use a reusable and pre-authorized [ephemeral key](https://tailscale.com/docs/features/ephemeral-nodes) for this purpose because it automatically cleans up devices after they shut down.\r\n\r\n![Tailscale's auth key generation page](https://tailscale.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fephemeral-keys.2d3fc94f.png&w=750&q=75)\r\n\r\nThe **Pre-approved** option will only display in the dialog if [device approval](https://tailscale.com/docs/features/access-control/device-management/device-approval) is enabled in your Tailscale network.\r\n\r\nNext, open a terminal and use the following command to create a [Koyeb Secret](https://www.koyeb.com/docs/reference/secrets) to securely store the auth key on Koyeb.\r\n\r\n```shell\r\nkoyeb secrets create TAILSCALE_AUTHKEY -v \"tskey-<key>\"\r\n```\r\n\r\nPass this Secret using an environment variable to your Koyeb Service to authenticate your application and join your tailnet.\r\n\r\n## [Step 2: Configure your Dockerfile to install Tailscale](https://tailscale.com/docs/install/cloud/koyeb\\#step-2-configure-your-dockerfile-to-install-tailscale)\r\n\r\nNext, build a [multistage Dockerfile](https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds) with two stages:\r\n\r\n- The first stage compiles and builds your application code.\r\n- The second stage pulls your application code and Tailscale into a final image that you can deploy to Koyeb.\r\n\r\nIn your `Dockerfile`:\r\n\r\n```docker\r\nFROM alpine:latest as builder\r\nWORKDIR /app\r\nCOPY . ./\r\n# This is where you build the application code as well.\r\n\r\n# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds\r\nFROM alpine:latest\r\nRUN apk update && apk add ca-certificates iptables ip6tables && rm -rf /var/cache/apk/*\r\n\r\n# Copy binary to production image.\r\nCOPY --from=builder /app/start.sh /app/start.sh\r\n\r\n# Copy Tailscale binaries from the tailscale image on Docker Hub.\r\nCOPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscaled /app/tailscaled\r\nCOPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscale /app/tailscale\r\nRUN mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale\r\n\r\n# Run on container startup.\r\nCMD [\"/app/start.sh\"]\r\n```\r\n\r\nThe Dockerfile specifies the `/app/start.sh` script as the initial process to run. This script starts Tailscale, then runs the application binary. This is where you use the `TAILSCALE_AUTHKEY` variable you defined when you generated an auth key.\r\n\r\nCreate a new file named `start.sh` in the root directory of your application and add the following content to the file to start Tailscale and launch your app:\r\n\r\n```shell\r\n#!/bin/sh\r\n# Start Tailscale\r\n/app/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/var/run/tailscale/tailscaled.sock &\r\n/app/tailscale up --ssh --auth-key=${TAILSCALE_AUTHKEY} --hostname=tailscale-on-koyeb\r\n\r\n# Start your app\r\n/app/my-app\r\n```\r\n\r\nYou pass the `--ssh` flag to `/app/tailscale up` to authorize SSH connections to the node. This will let you ensure everything is working as expected and let you connect to the node using SSH from your tailnet. Refer to [Tailscale SSH documentation](https://tailscale.com/docs/features/tailscale-ssh) for more information.\r\n\r\nSave the file. You're ready to deploy.\r\n\r\n## [Step 3: Deploy your app to Koyeb](https://tailscale.com/docs/install/cloud/koyeb\\#step-3-deploy-your-app-to-koyeb)\r\n\r\nTo deploy the application on Koyeb, run the following command from your application's root directory. This command creates and deploys a new Koyeb service that connects to your tailnet:\r\n\r\n```markup\r\nkoyeb deploy . myapp/main --instance-type small --region was --type worker --archive-builder docker --env TAILSCALE_AUTHKEY=@TAILSCALE_AUTHKEY --privileged\r\n```\r\n\r\nRun the following command to use SSH to confirm you can connect to the service:\r\n\r\n```shell\r\ntailscale ssh root@tailscale-on-koyeb\r\n```\r\n\r\nFor more information about Koyeb, the Koyeb CLI, resources, service types, and deployment options, refer to the [Koyeb documentation](https://www.koyeb.com/docs).\r\n\r\n## [Remove ephemeral nodes from a tailnet](https://tailscale.com/docs/install/cloud/koyeb\\#remove-ephemeral-nodes-from-a-tailnet)\r\n\r\nWhen an ephemeral node goes offline, it is automatically removed from your tailnet. You can also control ephemeral node removal using the [`tailscale logout`](https://tailscale.com/docs/reference/tailscale-cli#logout) command to either manually force the removal or incorporate the command into the [`tailscaled`](https://tailscale.com/docs/reference/tailscaled) Tailscale daemon. For more information, refer to [Ephemeral nodes](https://tailscale.com/docs/features/ephemeral-nodes#faq).\r\n\r\n![Project Logo](https://cdn.brandfetch.io/tailscale.com/fallback/lettermark/theme/dark/h/256/w/256/icon?c=1bfwsmEH20zzEfSNTed)\r\n\r\nAsk AI\r\n\r\nreCAPTCHA\r\n\r\nRecaptcha requires verification.\r\n\r\nprotected by **reCAPTCHA**\r\n","html":"<h1>Tailscale on Koyeb</h1>\n<p>Last validated: Jan 5, 2026</p>\n<p><a href=\"https://www.koyeb.com/\">Koyeb</a> is a serverless platform for seamlessly deploying AI applications and databases on high-performance infrastructure, including CPUs, GPUs, and Accelerators around the world.\r\nYou can add Tailscale to a Koyeb application to let your Koyeb Services communicate with other devices and services in your tailnet.</p>\n<h2><a href=\"https://tailscale.com/docs/install/cloud/koyeb#step-1-generate-an-auth-key-to-authenticate-your-service-on-koyeb\">Step 1: Generate an auth key to authenticate your Service on Koyeb</a></h2>\n<p>Start by <a href=\"https://tailscale.com/docs/features/access-control/auth-keys\">generating an auth key</a> to let your Koyeb service join your tailnet.</p>\n<p>Open the <a href=\"https://login.tailscale.com/admin/settings/keys\">Keys</a> page of the admin console and select <strong>Generate auth key</strong>. It's best practice to use a reusable and pre-authorized <a href=\"https://tailscale.com/docs/features/ephemeral-nodes\">ephemeral key</a> for this purpose because it automatically cleans up devices after they shut down.</p>\n<p><img src=\"https://tailscale.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fephemeral-keys.2d3fc94f.png&#x26;w=750&#x26;q=75\" alt=\"Tailscale&#x27;s auth key generation page\"></p>\n<p>The <strong>Pre-approved</strong> option will only display in the dialog if <a href=\"https://tailscale.com/docs/features/access-control/device-management/device-approval\">device approval</a> is enabled in your Tailscale network.</p>\n<p>Next, open a terminal and use the following command to create a <a href=\"https://www.koyeb.com/docs/reference/secrets\">Koyeb Secret</a> to securely store the auth key on Koyeb.</p>\n<pre><code class=\"language-shell\">koyeb secrets create TAILSCALE_AUTHKEY -v \"tskey-&#x3C;key>\"\n</code></pre>\n<p>Pass this Secret using an environment variable to your Koyeb Service to authenticate your application and join your tailnet.</p>\n<h2><a href=\"https://tailscale.com/docs/install/cloud/koyeb#step-2-configure-your-dockerfile-to-install-tailscale\">Step 2: Configure your Dockerfile to install Tailscale</a></h2>\n<p>Next, build a <a href=\"https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds\">multistage Dockerfile</a> with two stages:</p>\n<ul>\n<li>The first stage compiles and builds your application code.</li>\n<li>The second stage pulls your application code and Tailscale into a final image that you can deploy to Koyeb.</li>\n</ul>\n<p>In your <code>Dockerfile</code>:</p>\n<pre><code class=\"language-docker\">FROM alpine:latest as builder\r\nWORKDIR /app\r\nCOPY . ./\r\n# This is where you build the application code as well.\r\n\r\n# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds\r\nFROM alpine:latest\r\nRUN apk update &#x26;&#x26; apk add ca-certificates iptables ip6tables &#x26;&#x26; rm -rf /var/cache/apk/*\r\n\r\n# Copy binary to production image.\r\nCOPY --from=builder /app/start.sh /app/start.sh\r\n\r\n# Copy Tailscale binaries from the tailscale image on Docker Hub.\r\nCOPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscaled /app/tailscaled\r\nCOPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscale /app/tailscale\r\nRUN mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale\r\n\r\n# Run on container startup.\r\nCMD [\"/app/start.sh\"]\n</code></pre>\n<p>The Dockerfile specifies the <code>/app/start.sh</code> script as the initial process to run. This script starts Tailscale, then runs the application binary. This is where you use the <code>TAILSCALE_AUTHKEY</code> variable you defined when you generated an auth key.</p>\n<p>Create a new file named <code>start.sh</code> in the root directory of your application and add the following content to the file to start Tailscale and launch your app:</p>\n<pre><code class=\"language-shell\">#!/bin/sh\r\n# Start Tailscale\r\n/app/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/var/run/tailscale/tailscaled.sock &#x26;\r\n/app/tailscale up --ssh --auth-key=${TAILSCALE_AUTHKEY} --hostname=tailscale-on-koyeb\r\n\r\n# Start your app\r\n/app/my-app\n</code></pre>\n<p>You pass the <code>--ssh</code> flag to <code>/app/tailscale up</code> to authorize SSH connections to the node. This will let you ensure everything is working as expected and let you connect to the node using SSH from your tailnet. Refer to <a href=\"https://tailscale.com/docs/features/tailscale-ssh\">Tailscale SSH documentation</a> for more information.</p>\n<p>Save the file. You're ready to deploy.</p>\n<h2><a href=\"https://tailscale.com/docs/install/cloud/koyeb#step-3-deploy-your-app-to-koyeb\">Step 3: Deploy your app to Koyeb</a></h2>\n<p>To deploy the application on Koyeb, run the following command from your application's root directory. This command creates and deploys a new Koyeb service that connects to your tailnet:</p>\n<pre><code class=\"language-markup\">koyeb deploy . myapp/main --instance-type small --region was --type worker --archive-builder docker --env TAILSCALE_AUTHKEY=@TAILSCALE_AUTHKEY --privileged\n</code></pre>\n<p>Run the following command to use SSH to confirm you can connect to the service:</p>\n<pre><code class=\"language-shell\">tailscale ssh root@tailscale-on-koyeb\n</code></pre>\n<p>For more information about Koyeb, the Koyeb CLI, resources, service types, and deployment options, refer to the <a href=\"https://www.koyeb.com/docs\">Koyeb documentation</a>.</p>\n<h2><a href=\"https://tailscale.com/docs/install/cloud/koyeb#remove-ephemeral-nodes-from-a-tailnet\">Remove ephemeral nodes from a tailnet</a></h2>\n<p>When an ephemeral node goes offline, it is automatically removed from your tailnet. You can also control ephemeral node removal using the <a href=\"https://tailscale.com/docs/reference/tailscale-cli#logout\"><code>tailscale logout</code></a> command to either manually force the removal or incorporate the command into the <a href=\"https://tailscale.com/docs/reference/tailscaled\"><code>tailscaled</code></a> Tailscale daemon. For more information, refer to <a href=\"https://tailscale.com/docs/features/ephemeral-nodes#faq\">Ephemeral nodes</a>.</p>\n<p><img src=\"https://cdn.brandfetch.io/tailscale.com/fallback/lettermark/theme/dark/h/256/w/256/icon?c=1bfwsmEH20zzEfSNTed\" alt=\"Project Logo\"></p>\n<p>Ask AI</p>\n<p>reCAPTCHA</p>\n<p>Recaptcha requires verification.</p>\n<p>protected by <strong>reCAPTCHA</strong></p>\n"}