Skip to content

Instantly share code, notes, and snippets.

@valakhosravi
Created March 18, 2023 10:33
Show Gist options
  • Save valakhosravi/6cc176825c0f5722db490fb0eaf1e000 to your computer and use it in GitHub Desktop.
Save valakhosravi/6cc176825c0f5722db490fb0eaf1e000 to your computer and use it in GitHub Desktop.
To deploy a Next.js project to a Windows Server running IIS using Docker, you can follow these steps:
Build a Docker image for your Next.js application using a Dockerfile. Here's an example Dockerfile:
bash
# Use the official Node.js runtime as a parent image
FROM node:14
# Set the working directory to /app
WORKDIR /app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code to the working directory
COPY . .
# Build the application for production
RUN npm run build
# Expose port 3000
EXPOSE 3000
# Start the application
CMD ["npm", "start"]
Create a docker-compose.yml file that defines the Docker services for your application. Here's an example:
yaml
Copy code
version: "3"
services:
app:
build: .
ports:
- "3000:3000"
This configuration will create a Docker container for your Next.js application, and expose port 3000 to the host machine.
Start the Docker container using the following command:
Copy code
docker-compose up -d
This will start the Docker container in detached mode.
Create a new website in IIS and configure it to use a reverse proxy to route traffic to the Docker container. You can do this by following these steps:
Open IIS Manager and navigate to the server node.
Right-click the "Sites" folder and select "Add Website".
Configure the website with the following settings:
Site name: The name of your website.
Physical path: Any valid directory on the server.
Binding: Configure a binding for your website (e.g. http on port 80).
Right-click the website and select "URL Rewrite".
Click "Add Rule" and select "Reverse Proxy".
Configure the reverse proxy with the following settings:
Inbound rules: {REQUEST_URI}.
Outbound rules: {RESPONSE_BODY}.
Backend URL: http://app:3000.
Add the rule and save your changes.
Navigate to the URL of your website in a web browser to confirm that your Next.js application is running correctly.
That's it! You should now have a working Next.js application deployed to your Windows Server running IIS using Docker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment