Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

Commit 1f59fd2

Browse files
authored
Update Dockerfile
1 parent 9c103d1 commit 1f59fd2

1 file changed

Lines changed: 22 additions & 31 deletions

File tree

Dockerfile

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,67 @@
11
# =====================================================================================
22
# STAGE 1: The "Builder"
3-
# This stage uses Node.js to download the source files and build the static site.
3+
# This stage uses Node.js and your local source files to build the static site.
44
# =====================================================================================
55
FROM node:18-alpine AS builder
66

7-
# Install git, which is required by some tools.
8-
RUN apk add --no-cache git
9-
10-
# Install the necessary command-line tools globally.
11-
# gitbook-exporter: Downloads the Markdown source from a live GitBook site.
12-
# gitbook-cli: The official tool to build a static site from Markdown source.
13-
RUN npm install -g gitbook-exporter gitbook-cli
7+
# Install gitbook-cli, the official tool to build a static site from Markdown source.
8+
RUN npm install -g gitbook-cli
149

1510
# Set a working directory inside the container.
1611
WORKDIR /app
1712

18-
# Run the exporter to download the source files from the live GitBook site.
19-
# This creates a directory named after the book, e.g., "nebula".
20-
RUN gitbook-exporter https://nebulaclient.gitbook.io/nebula/
21-
22-
# Navigate into the newly created source directory.
23-
# The directory name is based on the book's title, so we use a wildcard.
24-
WORKDIR /app/nebula
13+
# Copy ALL your local files (Markdown, book.json, images, etc.) into the container.
14+
# This assumes the Dockerfile is at the root of your documentation source.
15+
COPY . .
2516

26-
# Install the required plugins for the book (defined in its book.json).
17+
# Run "gitbook install" to download any plugins defined in your book.json.
2718
RUN gitbook install
2819

29-
# Build the final, static HTML site.
30-
# This creates a "_book" directory containing all the files.
20+
# Run "gitbook build" to generate the final static HTML site.
21+
# This creates a "_book" directory containing all the files needed for hosting.
3122
RUN gitbook build
3223

3324
# =====================================================================================
3425
# STAGE 2: The "Runner"
35-
# This stage uses a minimal NGINX server to host the static files.
26+
# This stage uses a minimal NGINX server to host the static files. It is the final image.
3627
# =====================================================================================
3728
FROM nginx:1.25-alpine
3829

39-
# Set the port you want to expose.
30+
# Set the port to be used inside the container.
4031
ARG PORT=3587
4132
EXPOSE ${PORT}
4233

43-
# Remove the default NGINX configuration file.
34+
# Remove the default NGINX configuration to avoid conflicts.
4435
RUN rm /etc/nginx/conf.d/default.conf
4536

46-
# Copy the static HTML files generated in the "builder" stage
47-
# into the default NGINX web root directory.
48-
COPY --from=builder /app/nebula/_book /usr/share/nginx/html
37+
# Copy ONLY the built static HTML files from the "builder" stage
38+
# into the NGINX web root directory. This keeps the final image small.
39+
COPY --from=builder /app/_book /usr/share/nginx/html
4940

50-
# Copy our custom NGINX configuration.
51-
# This config tells NGINX to listen on our chosen port and serve the static files.
41+
# Create our simple NGINX configuration to serve the static site.
42+
# This is placed directly into the configuration directory.
5243
COPY <<EOF /etc/nginx/conf.d/gitbook.conf
5344
server {
45+
# Listen on the port specified during the build.
5446
listen ${PORT};
5547
server_name _;
5648

5749
# The root directory where our static files are located.
5850
root /usr/share/nginx/html;
5951
index index.html index.htm;
6052

61-
# Standard configuration for serving static files.
62-
# It tries to find a file matching the URI, then a directory,
63-
# and finally falls back to the index.html for clean URLs.
53+
# This is the crucial part for GitBook's "clean URLs".
54+
# It allows you to visit /my-page instead of /my-page.html.
6455
location / {
6556
try_files \$uri \$uri/ /index.html;
6657
}
6758

68-
# Optional: Add headers for security and caching.
59+
# Standard security headers.
6960
add_header X-Frame-Options "SAMEORIGIN";
7061
add_header X-Content-Type-Options "nosniff";
7162
add_header X-XSS-Protection "1; mode=block";
7263
}
7364
EOF
7465

75-
# Command to run NGINX in the foreground.
66+
# The command to start the NGINX server when the container runs.
7667
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)