3. A quick primer on Docker and AWS
4. What we’ll be deploying
5. Creating a Dockerfile
6. Building a docker image
7. Running a docker container
8. Creating the Registry (ECR) and uploading the app image to it
9. Creating a new task definition
10. Creating a cluster
11. Creating a service to run it
Writing code that does stuff is something most developers are familiar with. Sometimes, we need to take the responsibility of a SysAdmin or DevOps engineer and deploy our codebase to production where it will help a business solve problems for customers.
In this AWS docker node.js tutorial, I’ll show you how to dockerize a Node.js application and deploy it to Amazon Web Service (AWS) using Amazon ECR (Elastic Container Registry) and ECS (Elastic container service).
Node and Npm: Follow this link to install the latest versions.
Basic knowledge of Node.js.
Docker: The installation provides Docker Engine, Docker CLI client, and other cool stuff. Follow the instructions for your operating system. To check if the installation worked, fire this on the terminal:
The command above should display the version number. If it doesn’t, it means the installation didn’t complete properly.
4. AWS account: Sign up for a free tier. There is a waiting period to verify your phone number and bank card. After this, you will have access to the console.
5. AWS CLI: Follow the instructions for your OS. You need Python installed.
Docker is an open source software that allows you to pack an application together with the required dependencies and environment in a ‘Container’ that you can ship and run anywhere. It is independent of platforms or hardware, and therefore the containerized application can run in any environment in an isolated fashion.
Docker containers solve many issues, such as when an app works on a coworker's computer but doesn’t run on yours, or it works in the local development environment but doesn’t work when you deploy it to a server.
Amazon Web Services (AWS) offers a reliable, scalable, and inexpensive cloud computing service for businesses. As I mentioned before, this tutorial will focus on using the ECR and ECS services.
Let’s quickly build a sample Node.js app on docker that we’ll use for the purpose of this tutorial. It going to be very simple app.
Enter the following in your terminal:
// create a new directory mkdir sample-nodejs-app // change to new directory cd sample-nodejs-app // Initialize npm npm init -y // install express npm install express // create an server.js file touch server.js
Open server.js and paste the code below into it:
Start the app with:
Access it on http://localhost:3000. You should get Hello world from a Node.js app! displayed in your browser. The complete code is available on GitHub.
Now let’s take our very important app to production