Containerization
Learning objectives
- Knows the term containerization and knows what Docker is.
In the previous part, we deployed an application. The application had a Dockerfile
that for some reason helped the deployment. Here, you will learn a bit about containers.
Containerization refers to packaging an application so that it comes with the necessary operating system libraries and dependencies needed to run the application. An application within a container can be run practically anywhere, given that there exists support for the containerization software. One of the most commonly used software for containerization is Docker.
Here, we briefly visit how a Deno project that uses a database could be developed with the help of Docker. In the following subsections, we set up multiple containers: one that will run the Deno application, one that will run the database that the application uses, and one that will be responsible for database migrations.
Required software
To run the examples in this part, you need to have Docker and Docker compose installed.
To start working on the example, create a new folder that you will work in. Create a file called app.js
to the folder and add the following content to the file.
import { serve } from "https://deno.land/std@0.222.1/http/server.ts";
const handleRequest = (request) => {
return new Response("Meaning of life: 42");
};
serve(handleRequest, { port: 7777 });
Now, the folder structure is as follows.
tree --dirsfirst
.
└── app.js
The application should look quite familiar at this point. When we run the application on the command line, we notice that everything is in order.
ls
app.js
deno run --allow-net app.js
Opening up the browser and opening the address http://localhost:7777
shows the contents of the application. As usual, you may shut down the application by pressing Ctrl + C on the command line where you launched the application.