Skip to content

Instantly share code, notes, and snippets.

@fizerkhan
Last active June 26, 2024 09:36
Show Gist options
  • Save fizerkhan/029617fd75cdb167db7c to your computer and use it in GitHub Desktop.
Save fizerkhan/029617fd75cdb167db7c to your computer and use it in GitHub Desktop.
NodeJS and MongoDB app in Dokku with Digital Ocean

Steps:

  1. Create Digital Ocean Droplet with Dokku v0.3.16 on 14.04 image

  2. Login into the droplet and Update local settings.

    sh -c "echo 'LANG=en_US.UTF-8\nLC_ALL=en_US.UTF-8' > /etc/default/locale"
    reboot
  3. Open http://<ip_address_of_droplet> to configure dokku settings.

  4. Add dokku remote to your source code(from your development machine). In below code, app_name can be anything. It should be used when configure the database.

     ```shell
     git remote add dokku dokku@<ip_address_of_droplet>:<app_name>
     git push dokku master
     ```
    
  5. Install MongoDB dokku plugins in Digital Ocean droplet.

     ```shell
     git clone https://github.com/jeffutter/dokku-mongodb-plugin.git /var/lib/dokku/plugins/mongodb
     dokku plugins-install    
     ```
    
  6. Create database

     ```shell
         dokku mongodb:start
         dokku mongodb:create <app_name>
     ```
    
  7. Change your MongoDB url to process.env.MONGO_URL and commit your source code. (You must push app again to take mongodb url) It will print the URL of the app. You can visit the app in browser.

     ```shell
     git push dokku master
     ```
    
  8. You can also view mongodb config

     ```shell
     dokku config <app_name>
     ```
    
@malixsys
Copy link

on 0.3.x

cd /var/lib/dokku/plugins git clone https://github.com/dokku/dokku-mongo.git mongo dokku plugins-install

on 0.4.x

dokku plugin:install https://github.com/dokku/dokku-mongo.git mongo

@malixsys
Copy link

Also, now, dokku mongo:link YOUR_DB YOUR_APP will create a process.env.MONGO_URL in the YOUR_APP container

@antonio-th
Copy link

Hi, is it possible to scale the service to more instances? If so, how can I do that?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment