Dockerizing headless Hashnode starter-kit

Sandeep Panda

·

·

317 views

In case you're not aware, headless Hashnode is a purpose-built CMS that allows developers to utilize Hashnode's fantastic editor and CMS while still having complete control over the UI customization. To simplify the process, we also provide a Next.js starter kit that anyone can easily deploy on their preferred cloud platform.

While working with several users, I realized they could benefit from a Dockerfile that allows them to easily deploy their own blog. So, I created this Dockerfile quickly:

FROM node:18-alpine

COPY . /app

# Set the working directory
WORKDIR /app

# Install pnpm
RUN npm install -g pnpm

# By default, use the enterprise theme
ARG THEME=enterprise

WORKDIR /app/packages/blog-starter-kit/themes/${THEME}

RUN pnpm install --frozen-lockfile

RUN pnpm build

# Expose the port Next.js runs on
EXPOSE 3000

# Run the Next.js start script
CMD ["pnpm", "start"]

Now, let's see how you can see a live demo of your own blog in 4 easy steps:

Step 1

Fork the starter-kit from GitHub.

Step 2

In your terminal, cd into either enterprise, personal, or hashnode theme:

cd packages/blog-starter-kit/themes
cd <theme>

Step 3

Open .env.example, and copy the values into .env.local in the same directory. Replace the value of NEXT_PUBLIC_HASHNODE_PUBLICATION_HOST with your blog's hostname.

Step 4

Now cd into the root of the project, and run the following commands to run the app:

cd ../../../..
docker build --build-arg THEME=personal -t hn-blog .
docker run -d -p 3000:3000 hn-blog

With these steps completed, you should now be able to view a live demo. Simply open your browser and enter the URL http://localhost:3000!

1 comment
Add a comment