Skip to content

Instantly share code, notes, and snippets.

@andriilive
Last active September 22, 2024 05:20
Show Gist options
  • Select an option

  • Save andriilive/38e0c30ad0e68e01d0bfc5250998de50 to your computer and use it in GitHub Desktop.

Select an option

Save andriilive/38e0c30ad0e68e01d0bfc5250998de50 to your computer and use it in GitHub Desktop.
Self-hosted with EasyPanel Next.js in Docker

Self-hosted with EasyPanel Next.js in Docker

StandWithUkraine

The guide on NextJs with docker project setup on EasyPanel

Visit repository: https://github.com/digitalandyeu/next-with-docker

1. Create a new app instance

Source from a github digitalandyeu / next-with-docker repo at the main branch

CleanShot 2024-09-22 at 00 36 30@2x

Chose Dockerfile build method

CleanShot 2024-09-22 at 00 43 59@2x

2. First deploy

The above step configuration is enough to start your app, now. Because the first-deploy.sh script is missing, in our build do manually:

  1. Stop the app
  2. Force rebuild
  3. Press Deploy
  4. Start the app

Now You should see your app running and available at default domain:

CleanShot 2024-09-22 at 00 51 36@2x

Visit default public domain from Domains section:

CleanShot 2024-09-22 at 00 52 31@2x

3. Add the .env file

Navigate to Enviorment section and paste your enviorment variables

# https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
NEXT_PUBLIC_DOMAIN=next.digitalandy.eu
NEXT_PUBLIC_URL=https://$NEXT_PUBLIC_DOMAIN
PORT=3000

Turn on the Create .env file option and save

CleanShot 2024-09-22 at 01 10 35@2x

4. Configure the domain

Navigate to Domains section and

  1. attach domain, for example next.digitalandy.eu at port 3000 with https enabled
  2. make your domain primary by clicking the star icon
  3. remove the default public domain attached by easypanel

CleanShot 2024-09-22 at 00 56 25@2x

Easypanel handles the http -> https redirect + cert & auto renewal for you

5. Setup github auto-deployments

  1. Deployment Trigger url

Copy the Deployment Trigger url value from Deployments section

CleanShot 2024-09-22 at 01 32 40@2x

Deployment Trigger url example: http://11.11.11.11:3000/api/deploy/73xxxx3a

  1. Configure the repository at GitHub

Click settings -> webhooks -> add new, then follow the below pattern:

CleanShot 2024-09-22 at 01 27 33@2x

Payload URL: Deployment Trigger url
Content Type: application/json
SSL Verification: disable
Event: just push event
Active: checked

6. Deploy and test

Trigger the new deploy, validate if port has changed to the value we provided earlier in .env file

CleanShot 2024-09-22 at 01 46 23@2x

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