Skip to content

Instantly share code, notes, and snippets.

@aoirint
Last active July 6, 2023 03:23
Show Gist options
  • Save aoirint/4fb0859aecf25a069d357877427b90b9 to your computer and use it in GitHub Desktop.
Save aoirint/4fb0859aecf25a069d357877427b90b9 to your computer and use it in GitHub Desktop.
Hello World Deno (Docker)

TODO: no cache for Docker container build

$ deno --version                         
deno 1.0.0
v8 8.4.300
typescript 3.9.2
# run as root
docker build . -t deno
docker run --rm -v `pwd`:/code -it deno
docker run --rm -v `pwd`:/code -p 127.0.0.1:8100:8000 -it deno
# in the Docker container
deno --version
deno run script.ts
deno run https://deno.land/std/examples/welcome.ts
deno run --allow-net serve_web.ts
FROM ubuntu:bionic
WORKDIR /code
RUN apt update && apt install -y curl unzip
RUN curl -fsSL https://deno.land/x/install/install.sh | sh
RUN echo "export PATH=\$HOME/.deno/bin:\$PATH" >> $HOME/.bashrc
import { serve } from "https://deno.land/std@0.50.0/http/server.ts";
// http://localhost:8000/
const s = serve({ port: 8000, });
for await (const req of s) {
req.respond({
body: 'Hello Deno!\n',
});
}
import { serve } from "https://deno.land/std@0.50.0/http/server.ts";
// http://localhost:8000/
const s = serve({ port: 8000, });
for await (const req of s) {
const headers = new Headers();
headers.set('content-type', 'text/plain; charset=utf-8');
req.respond({
headers: headers,
body: 'Hello 🍣!\n',
});
}
console.log('Hello 🍣!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment