Deno with Docker and EC2
Learn how to dockerise your Deno application and run it on Amazon EC2 instance.
Deno
Deno is a simple, modern, and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.
Why Docker?
Docker is a great tool to deploy your application in a container. A container stores your application installs all the dependencies, and independently runs the application on a container.
Containers are more agile than virtual machines, thanks to the underlying base host operating system that makes the operations much faster.
Why EC2?
Amazon Web Services provides the most powerful tools for cloud computing. The EC2 can serve as a virtual server in the AWS cloud, practically unlimited sets of virtual machines. You can set up and configure the operating systems and applications that run on your system.
Using EC2 over any other services is a no brainer. The EC2 instances are highly scalable, that’s why even the biggest tech giants and companies like Adobe Systems, 21st Century Fox, AirAsia, Airbnb, etc rely on EC2 to host their platform. Elastic load balancing is another great feature that AWS has to offer, it automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, IP addresses, and Lambda functions. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones. The advantages list goes on and on. You can read more about it on
Dockerising is a very good practice, every system has its own set of configuration and settings, it is impossible to transfer every system settings of the system on which application is built. Docker is here to save the day! It stores the application and its dependencies that runs on an independent container so anyone in the world can access the application.
Enough of the chit chat, Let’s get going!
First thing’s first! Download Docker desktop from
you can refer to this link
Set up your Deno application
A deno working directory would look something like this :
Create a Dockerfile with these set of instructions
FROM We set our base image from hayd/deno:alpine-1.1.1 image
WORKDIR specifies the working directory
COPY copies project from our host system to workdir of the container
USER specify username
CMD specifies a set of instructions for the command line. To run the app, docker will look for CMD commands.
Expose, exposing your application to a specific port
After this setup, run the following command:
$ docker build -t <username>/<application name>$ docker run -it -p 8000:8000 <username>/<application name>
Voila! your docker container is up and running now. You can push this app to the docker hub and keep track of the tags and version.
Time for EC2
Sign-in into your AWS account, if you aren’t already signed up, create a new account on
Search for EC2 service
From the Instances option > launch new instance
1: Choose the AMI as per your requirement, I’ll be using Amazon Linux 2 AMI
2: Choosing the Instance type, I’ll be using the free tier.
3: You skip other steps and jump directly onto configuring a security group
Add a custom TCP and match it with the port you’ll be running your application on.
Adding a Key-pair
This is the most crucial step. This key pair is the gateway to our instance from our computer.
Download this key-pair file in a known location, this is where you will be accessing your instance from.
Phewwww. Now that you have everything set up, its time to SSH into our instance
Make sure you have PuTTY downloaded, check this link out
Now, open your terminal. Change the directory to the folder where you have stored key pair.
In “connect to your instance” option copy the following command :
Boom! now you can access your instance from your computer, how cool is that?
Now we have to run the Docker container in our system.
Installing docker
$ sudo yum install docker
$ sudo service docker start
Deploying container
$ sudo docker login
Username:
Password:$docker run -it -p 8000:8000 --restart=always <username>/<repository name>
This will start downloading all your application dependencies and modules and store it in your instance.
Connect to the specified port
Voila! You have successfully deployed your instance, any computer in the world can access this port and run your application!
Sample repo:
Hope you got to learn something new, let me know if you face any issue.