# Deno with Docker and EC2

#### Learn how to dockerise your Deno application and run it on Amazon EC2 instance.

![](https://cdn-images-1.medium.com/max/1600/1*_xgu4wtQVqn3n6ETQkdYFw.jpeg align="center")

### 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.

![](https://cdn-images-1.medium.com/max/1600/1*WUH4iiAUvTzzx7jkKX5vsA.jpeg align="center")

source:[https://www.youtube.com/watch?v=TvnZTi\_gaNc](https://www.youtube.com/watch?v=TvnZTi_gaNc)

Containers are more agile than virtual machines, thanks to the underlying base host operating system that makes the operations much faster.

### Why EC2?

![](https://cdn-images-1.medium.com/max/1600/1*dfEIFZvuNC7ljFy2QNurLA.png align="center")

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 [https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html)

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** [https://www.docker.com/products/docker-desktop](https://www.docker.com/products/docker-desktop)

you can refer to this link [https://www.youtube.com/watch?v=\_9AWYlt86B8](https://www.youtube.com/watch?v=_9AWYlt86B8)

#### Set up your Deno application

A deno working directory would look something like this :

![](https://cdn-images-1.medium.com/max/1600/1*IsYJDpotk32FuR2qGZ6IpQ.png align="center")

**Create a Dockerfile** with these set of instructions

![](https://cdn-images-1.medium.com/max/1600/1*sjeR4orJEl_2MB9KEsnrcA.png align="center")

**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:

```plaintext
$ docker build -t <username>/<application name>
```

```plaintext
$ 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 [http://aws.amazon.com](http://aws.amazon.com/)

**Search for EC2 service**

![](https://cdn-images-1.medium.com/max/1600/1*NYbmbY6WAz-Siiq3XO40_A.png align="center")

#### From the Instances option &gt; launch new instance

1: Choose the AMI as per your requirement, I’ll be using Amazon Linux 2 AMI

![](https://cdn-images-1.medium.com/max/1600/1*eE8R6JnmujjAyQaXLq5KLw.png align="center")

2: Choosing the Instance type, I’ll be using the free tier.

![](https://cdn-images-1.medium.com/max/1600/1*47i7Uy2j0Fc4cIEDeBUAEQ.png align="center")

3: You skip other steps and jump directly onto configuring a security group

![](https://cdn-images-1.medium.com/max/1600/1*4onS5QmjMcXNdJbB1yF25g.png align="center")

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.

![](https://cdn-images-1.medium.com/max/1600/1*hH24clgK68_DbphZQhXulw.png align="center")

Download this key-pair file in a known location, this is where you will be accessing your instance from.

![](https://cdn-images-1.medium.com/max/1600/1*4BB7EfCZo0pLavdCGfokNA.png align="center")

---

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 [https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html?icmpid=docs\_ec2\_console](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html?icmpid=docs_ec2_console)

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 :

![](https://cdn-images-1.medium.com/max/1600/1*cOUIsRTlE6-N4K8x-jnxmg.png align="center")

![](https://cdn-images-1.medium.com/max/1600/1*fEBjDIXkawLlb0AB_cjo_g.png align="left")

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

```plaintext
$ sudo yum install docker
$ sudo service docker start
```

#### Deploying container

```plaintext
$ sudo docker login 
Username:
Password:
```

```plaintext
$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.

![](https://cdn-images-1.medium.com/max/1600/1*PYdTmh54r91SDadRE6ia9Q.png align="center")

Connect to the specified port

![](https://cdn-images-1.medium.com/max/1600/1*1KZfT_0n2zyEi0v1IzST2g.png align="center")

Voila! You have successfully deployed your instance, any computer in the world can access this port and run your application!

Sample repo: [https://github.com/N0v0cain3/NASA-CRUD](https://github.com/N0v0cain3/NASA-CRUD)

Hope you got to learn something new, let me know if you face any issue.

[**Shivam Mehta — Back End Developer — Kaloory | LinkedIn**  
*View Shivam Mehta’s profile on LinkedIn, the world’s largest professional community. Shivam has 3 jobs listed on their…*www.linkedin.com](https://www.linkedin.com/in/shivam-mehta-b09724189/)
