Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
⌘K
Up or down tonavigateEnter toselectEscape toclose
On this page

Deploying Deno with Docker

Video descriptionJump to heading

See how to deploy Deno applications with Docker to a compatible cloudenvironment.

ResourcesJump to heading

Transcript and codeJump to heading

Deno has made a lot of things seem easy: linting, formatting, interoperabilitywith the Node ecosystem, testing, TypeScript, but how about deployment? How easyis it to get Deno running in production? Pretty easy!

Let’s start with a look at our app. It’s an app that provides us with someinformation about trees. On the homepage we get some text At the trees route, weget some JSON At the dynamic route based on the tree’s id, we get informationabout that single tree.

import{ Hono}from"jsr:@hono/hono";const app=newHono();interfaceTree{  id:string;  species:string;  age:number;  location:string;}const oak: Tree={  id:"1",  species:"oak",  age:3,  location:"Jim's Park",};const maple: Tree={  id:"2",  species:"maple",  age:5,  location:"Betty's Garden",};const trees: Tree[]=[oak, maple];app.get("/",(c)=>{return c.text("🌲 🌳 The Trees Welcome You! 🌲 🌳");});app.get("/trees",(c)=>{return c.json(trees);});app.get("/trees/:id",(c)=>{const id= c.req.param("id");const tree= trees.find((tree)=> tree.id=== id);if(!tree)return c.json({ message:"That tree isn't here!"},404);return c.json(tree);});Deno.serve(app.fetch);

Run Locally with DockerJump to heading

Make sure that Docker is installed on your machine. In your terminal or commandprompt, you can run docker and if you get a big list of commands, you have it.If not, head over tohttps://www.docker.com/ and download it based on youroperating system.

Test run docker:Jump to heading

docker

Then run the command to get running onlocalhost:8000 with Docker

docker run-it-p8000:8000-v$PWD:/my-deno-project denoland/deno:2.0.2 run--allow-net /my-deno-project/main.ts

Visit the app running atlocalhost:8000

It’s also possible to run this with a docker config file.

FROMdenoland/deno:2.0.2# The port that your application listens to.EXPOSE 8000WORKDIR /app# Prefer not to run as root.USER deno# These steps will be re-run upon each file change in your working directory:COPY . .# Compile the main app so that it doesn't need to be compiled each startup/entry.RUN deno cache main.ts# Warmup cachesRUN timeout 10s deno -A main.ts || [ $? -eq 124 ] || exit 1CMD ["run", "--allow-net", "main.ts"]

Then build it

docker build-t my-deno-project.

From there, you can deploy the app to your hosting provider of choice. I’m goingto usefly.io today.

Deploy tofly.ioJump to heading

If you haven’t worked with fly before, it’s a cloud platform that allows you todeploy and run fullstack apps. They run in multiple regions throughout the worldwhich makes them a pretty nice option.https://fly.io/

Install FlyJump to heading

Install with curl

curl-L https://fly.io/install.sh|sh

Log in with Fly via CLIJump to heading

fly auth login

This will open the browser for you to log into your account (or create one ifyou haven’t already). Then we’ll launch the app with fly using:

flyctl launch

This will generate a fly.toml file for the app, and you can choose differentsettings if you’d like to. And more importantly it will launch it! We’ll justwait for the process to complete, and we should be able to view our app runningat that location.

So with Deno, we can use Docker to containerize the app and with Fly we can getthe app hosted in production in just a few minutes.

More information on working with DockerJump to heading

For a closer look at Deno's support of Docker, including best practices, runningtests with Docker, using workspaces, and more, please take a look at ourDeno and Docker reference documentation.

Find more videos in theExamples page and on ourYouTube channel.

Did you find what you needed?

What can we do to improve this page?

If provided, you'll be @mentioned in the created GitHub issue

Privacy policy

[8]ページ先頭

©2009-2025 Movatter.jp