DEV Community

Francesco Ciulla
Francesco Ciulla

Posted on

DOCKER+DENO episode 2: Containerize a Deno FULL REST API from Traversymedia Deno Crash course

To follow Please check the Deno crash course by Traversymedia
https://www.youtube.com/watch?v=NHHhiqwcfRM

Deno is the buzzword of the moment, and we still don't know how it will end.

Honestly, I am a fan of node, but I was intrigued, after following the Deno Crash Course, by Traversymedia I tried to containerize it with docker.

Warning!
this example is based on this docker image https://hub.docker.com/r/hayd/deno

Which is not an official deno repository

Github Repository: https://github.com/FrancescoXX/deno-docker-api

JUST TEST

docker run -it --init -p 8000:8000 --init francescoxx/deno-docker:0.0.2
Enter fullscreen mode Exit fullscreen mode

Short version

you can just clone the repository

git clone https://github.com/FrancescoXX/deno-docker-api
Enter fullscreen mode Exit fullscreen mode

navigate to the folder where the docker-compose.yml is located, and run

docker-compose up --build
Enter fullscreen mode Exit fullscreen mode

Done!


Long version

If you want to follow along, and you use Visual Studio Code, I suggest you install this extension:

Alt Text


Step 1

Follow the traversymedia Deno Crash course
https://www.youtube.com/watch?v=NHHhiqwcfRM


Step 2

then, we create a very simple Dockerfile, using the hayd/alpine-deno:1.0.0 image

FROM hayd/alpine-deno:1.0.0

EXPOSE 8000

WORKDIR /app

USER deno

COPY . .

CMD ["run", "--allow-net", "server.ts"]
Enter fullscreen mode Exit fullscreen mode

STEP 3

And last, we create a very simple docker-compose.yml file, which is no needed for now, but it could be useful in the future, for example, if we start using a database or some other services

We define port 8000 as both inner and outer one and a default network

version: "3.7"

services:
  deno:
    image: "deno-docker:0.0.2"
    build: .
    ports:
      - "8000:8000"
    networks: 
      - deno

networks:
  deno: {}
Enter fullscreen mode Exit fullscreen mode

from the folder where the docker-compose.yml file is located, we build the image:

docker-compose build
Enter fullscreen mode Exit fullscreen mode

And finally, we can launch the service with this command

docker-compose up deno
Enter fullscreen mode Exit fullscreen mode

visit localhost:8000 from a browser

Traversymedia Deno Crash course:

https://www.youtube.com/watch?v=NHHhiqwcfRM

Github Repository: Github Repository: https://github.com/FrancescoXX/deno-docker-api

Final note: this doesn't seem that useful, as we are just simply containerizing a deno rest api.
Things will get interesting on the database part :)

Top comments (5)

Collapse
 
dthompsondev profile image
Danny Thompson

This was fantastic!

Collapse
 
francescoxx profile image
Francesco Ciulla

Thank you!

Collapse
 
chrisdixon161 profile image
Chris Dixon

Thanks Francesco, great read!

Collapse
 
francescoxx profile image
Francesco Ciulla

Thanks Chris!

Collapse
 
saswatamcode profile image
Saswata Mukherjee

Awesome article!!