Using Deno with Docker & Docker Compose

#docker#container#deno

Chris Brocklesby

Using Deno with Docker & Docker Compose create the three files below...

main.js

import { Application } from "https://deno.land/x/oak@11.1.0/mod.ts";

const app = new Application();

app.use((ctx) => {
  ctx.response.body = "Hello from Deno!";
});

await app.listen({ port: 8000 });

Dockerfile

FROM denoland/deno

EXPOSE 8000

WORKDIR /app

ADD . /app

RUN deno cache main.js

CMD ["run", "--allow-net", "main.js"]

docker-compose.yml

version: '3'

services:
  web:
    build: .
    container_name: deno-container
    image: deno-image
    ports:
      - "8000:8000"

Let's test this locally by running docker compose -f docker-compose.yml build, then docker compose up, and going to localhost:8000.

Chris BrocklesbyHead of Technology, Software Engineer, Technology lover and Family man based in Mapua, Tasman in New Zealand (Originally from Swansea UK).