Step-by-Step Guide to Deploying a React/Nextjs/Static App on a Dokku Server in AWS EC2 Instance
Tags: devops, dokku, react, aws
Published: 2023-01-31 11:39:04



## 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:
```ssh
# 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
```

**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
# ssh dokku@<ip_add> <DOKKU_COMMAND>
  ssh dokku@10.10.10.10 apps:create hobby
```

**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
 # ssh dokku@<IP_ADD> domains:remove-global <SERVER_ADDRESS>  
   ssh dokku@10.10.10.10 domains:remove-global example-address.compute.internal

```

- Add the global domain:
```ssh
 # ssh dokku@<IP_ADD> domains:add-global <DOMAIN_NAME>  
   ssh dokku@10.10.10.10 domains:add-global example.com
```

**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:
```ssh
 sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
 dokku config:set --global DOKKU_LETSENCRYPT_EMAIL=your-email@your.domain.com
```

**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:
   
```ssh
 # git remote add <repo_name> dokku@<ip_add/domain>:<app_name>
   git remote add dokku dokku@10.10.10.10:hobby
```

- Create an app in the Dokku server from your local machine:
  
```ssh
  # ssh dokku@<ip_add> apps:create <app_name>
    ssh dokku@10.10.10.10 apps:create hobby

```

- Deploy the Git repository in the Dokku server:
```ssh
 # git push <REPOSITORY_NAME> <BRANCH_NAME>
   git push dokku main
```

**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
ssh dokku@10.10.10.10 domains:report hobby
```

- Set the domain for the app:
```ssh
 dokku domains:set hobby test-preview.intellidigital.com
```

- Add the domain remotely:
```ssh
ssh dokku@10.10.10.10 domains:add hobby hobby.theme-preview.intellidigital.com
```

**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
ssh dokku@10.10.10.10 letsencrypt:set hobby email maskawat.masuk@intelli.global
```

- Enable the SSL for the app:
```ssh
ssh dokku@10.10.10.10 letsencrypt:enable hobby
```

- Automatically update the letsencrypt certificate
```ssh
ssh dokku@10.10.10.10 letsencrypt:cron-job --add
```