Learn how to create a Docker configuration for a Deno web server and how to make your Deno application available on the internet.

Prerequisites

  • Docker installed on your server and local machine
  • An Ubuntu server, you can get one from DigitalOcean
  • Basic understanding of git
  • Basic understanding of the command line interface

In this step, you will be creating a simple Deno application to display hello world. Unlike NodeJS, you do not need to run npm init to create a new application. You can simply create a TypeScript file and start coding away.

To begin, create a new directory named deno-deploy on your local machine, by running:

mkdir deno-deploy

Change directory to deno-deploy by running:

cd deno-deploy

Create a new file named server.ts within the deno-deploy directory by running:

touch server.ts

Note: alternatively, you could use your favourite editor to create this file.

Open server.ts with your preferred editor and paste and save the following code snippet:

import { serve } from "https://deno.land/std@0.53.0/http/server.ts";

const server = serve({ port: 8000 });

console.log("Now serving on port 8000 🔥");

for await (const req of server) {
    req.respond({ body: "Hello World"});
}

The snippet above will create a Deno server and serves the content Hello World on port 8000.

Create a Docker configuration

Create a Dockerfile

In this step, you will set up the Docker configuration for your Deno application. First, you will create a new file named Dockerfile via the terminal by running:

touch Dockerfile

Open Dockerfile with your preferred text editor then paste and save the following snippet:

FROM hayd/deno:latest

EXPOSE 8000

WORKDIR /app

ADD . /app

RUN deno cache server.ts

CMD ["run", "--allow-net", "server.ts"]

Let’s break down what these lines in our Dockerfile will do when executed:

#deno #docker #typescript #node

How to Deploy Deno Applications to Production
14.20 GEEK