DEV Community

Cover image for Step-by-Step Guide to Deploying a React/Nextjs/Static App on a Dokku Server in AWS EC2 Instance
MHMasuk
MHMasuk

Posted on • Updated on

Step-by-Step Guide to Deploying a React/Nextjs/Static App on a Dokku Server in AWS EC2 Instance

Setting Up Dokku in AWS EC2


Dokku is a popular open-source platform that simplifies the process of deploying and managing applications. In this guide, we'll show you how to set up Dokku in an Amazon Web Services (AWS) EC2 instance.

Step 1: Pass the Public SSH Key to the AWS Server
Use the following command to pass the public SSH key to the AWS server:

# cat <public_key_dir> | ssh -i <aws_key_dir> <username>@<ip_add/domain> sudo dokku ssh-keys:add <KEY_NAME>
  cat ~/.ssh/id_rsa.pub | ssh -i "intelli_masuk.pem" ubuntu@example-address.compute.internal.compute.amazonaws.com sudo dokku ssh-keys:add admin
Enter fullscreen mode Exit fullscreen mode

Step 2: Remote Dokku Command in a Server from Local Machine

To run a remote Dokku command in the server from your local machine, use the following command:

# ssh dokku@<ip_add> <DOKKU_COMMAND>
  ssh dokku@10.10.10.10 apps:create hobby
Enter fullscreen mode Exit fullscreen mode

Step 3: Setting Up the Global Domain for a Dokku Server
To set up the global domain for a Dokku server, follow these steps:

  • Remove the global domain:
 # ssh dokku@<IP_ADD> domains:remove-global <SERVER_ADDRESS>  
   ssh dokku@10.10.10.10 domains:remove-global example-address.compute.internal

Enter fullscreen mode Exit fullscreen mode
  • Add the global domain:
 # ssh dokku@<IP_ADD> domains:add-global <DOMAIN_NAME>  
   ssh dokku@10.10.10.10 domains:add-global example.com
Enter fullscreen mode Exit fullscreen mode

Step 4: Setting Up the SSL Certificate Plugin for a New Dokku Server

To set up the Dokku Let's Encrypt plugin for the first time, use the following commands:

 sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
 dokku config:set --global DOKKU_LETSENCRYPT_EMAIL=your-email@your.domain.com
Enter fullscreen mode Exit fullscreen mode

Step 5: Deploying an Application in Dokku Server
To deploy an application in the Dokku server, follow these steps:

  • Add a Git repository in the Dokku server:
 # git remote add <repo_name> dokku@<ip_add/domain>:<app_name>
   git remote add dokku dokku@10.10.10.10:hobby
Enter fullscreen mode Exit fullscreen mode
  • Create an app in the Dokku server from your local machine:
  # ssh dokku@<ip_add> apps:create <app_name>
    ssh dokku@10.10.10.10 apps:create hobby

Enter fullscreen mode Exit fullscreen mode
  • Deploy the Git repository in the Dokku server:
 # git push <REPOSITORY_NAME> <BRANCH_NAME>
   git push dokku main
Enter fullscreen mode Exit fullscreen mode

Step 6: Setting Up a Domain for an App
To set up a domain for an app, follow these steps:

  • Report the app's domains:
ssh dokku@10.10.10.10 domains:report hobby
Enter fullscreen mode Exit fullscreen mode
  • Set the domain for the app:
 dokku domains:set hobby test-preview.intellidigital.com
Enter fullscreen mode Exit fullscreen mode
  • Add the domain remotely:
ssh dokku@10.10.10.10 domains:add hobby hobby.theme-preview.intellidigital.com
Enter fullscreen mode Exit fullscreen mode

Step 7: Enabling the SSL Certificate for an App
To enable the SSL certificate for an app, follow these steps:

  • Set the email to get the SSL certificate:
ssh dokku@10.10.10.10 letsencrypt:set hobby email maskawat.masuk@intelli.global
Enter fullscreen mode Exit fullscreen mode
  • Enable the SSL for the app:
ssh dokku@10.10.10.10 letsencrypt:enable hobby
Enter fullscreen mode Exit fullscreen mode
  • Automatically update the letsencrypt certificate
ssh dokku@10.10.10.10 letsencrypt:cron-job --add
Enter fullscreen mode Exit fullscreen mode

Top comments (0)