Skip to content

Commit ab3dc5c

Browse files
docs: small adjustments (t3-oss#266)
* docs: add instructions on building docker image to readme (t3-oss#265) * Add instructions on building docker image Following the same method given in NextJs examples * fix: prettier check run prettier format to fix formatting issues * docs: small adjustments
1 parent 96dabb6 commit ab3dc5c

File tree

1 file changed

+71
-57
lines changed

1 file changed

+71
-57
lines changed

template/base/README.md

+71-57
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ If you are not familiar with the different technologies used in this project, pl
2121

2222
## How do I deploy this?
2323

24+
### Vercel
25+
2426
We recommend deploying to [Vercel](https://vercel.com/?utm_source=t3-oss&utm_campaign=oss). It makes it super easy to deploy NextJs apps.
2527

2628
- Push your code to a GitHub repository.
@@ -30,85 +32,97 @@ We recommend deploying to [Vercel](https://vercel.com/?utm_source=t3-oss&utm_cam
3032
- Click **Deploy**
3133
- Now whenever you push a change to your repository, Vercel will automatically redeploy your website!
3234

35+
### Docker
36+
3337
You can also dockerize this stack and deploy a container.
3438

35-
- In your next.config.mjs, add the `output: "standalone"` option to your config.
36-
- Create a `.dockerignore` file with the following contents:
37-
```
38-
Dockerfile
39-
.dockerignore
40-
node_modules
41-
npm-debug.log
42-
README.md
43-
.next
44-
.git
45-
```
46-
- Create a `Dockerfile` with the following contents:
47-
48-
```
49-
# Install dependencies only when needed
50-
FROM node:16-alpine AS deps
51-
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
52-
RUN apk add --no-cache libc6-compat
53-
WORKDIR /app
54-
55-
# Install dependencies based on the preferred package manager
56-
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
57-
RUN \
39+
1. In your [next.config.mjs](./next.config.mjs), add the `output: "standalone"` option to your config.
40+
2. Create a `.dockerignore` file with the following contents:
41+
<details>
42+
<summary>.dockerignore</summary>
43+
44+
```
45+
Dockerfile
46+
.dockerignore
47+
node_modules
48+
npm-debug.log
49+
README.md
50+
.next
51+
.git
52+
```
53+
54+
</details>
55+
56+
3. Create a `Dockerfile` with the following contents:
57+
<details>
58+
<summary>Dockerfile</summary>
59+
60+
```Dockerfile
61+
# Install dependencies only when needed
62+
FROM node:16-alpine AS deps
63+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
64+
RUN apk add --no-cache libc6-compat
65+
WORKDIR /app
66+
67+
# Install dependencies based on the preferred package manager
68+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
69+
RUN \
5870
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
5971
elif [ -f package-lock.json ]; then npm ci; \
6072
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
6173
else echo "Lockfile not found." && exit 1; \
6274
fi
6375

6476

65-
# Rebuild the source code only when needed
66-
FROM node:16-alpine AS builder
67-
WORKDIR /app
68-
COPY --from=deps /app/node_modules ./node_modules
69-
COPY . .
77+
# Rebuild the source code only when needed
78+
FROM node:16-alpine AS builder
79+
WORKDIR /app
80+
COPY --from=deps /app/node_modules ./node_modules
81+
COPY . .
82+
83+
# Next.js collects completely anonymous telemetry data about general usage.
84+
# Learn more here: https://nextjs.org/telemetry
85+
# Uncomment the following line in case you want to disable telemetry during the build.
86+
# ENV NEXT_TELEMETRY_DISABLED 1
7087

71-
# Next.js collects completely anonymous telemetry data about general usage.
72-
# Learn more here: https://nextjs.org/telemetry
73-
# Uncomment the following line in case you want to disable telemetry during the build.
74-
# ENV NEXT_TELEMETRY_DISABLED 1
88+
RUN yarn build
7589

76-
RUN yarn build
90+
# If using npm comment out above and use below instead
91+
# RUN npm run build
7792

78-
# If using npm comment out above and use below instead
79-
# RUN npm run build
93+
# Production image, copy all the files and run next
94+
FROM node:16-alpine AS runner
95+
WORKDIR /app
8096

81-
# Production image, copy all the files and run next
82-
FROM node:16-alpine AS runner
83-
WORKDIR /app
97+
ENV NODE_ENV production
98+
# Uncomment the following line in case you want to disable telemetry during runtime.
99+
# ENV NEXT_TELEMETRY_DISABLED 1
84100

85-
ENV NODE_ENV production
86-
# Uncomment the following line in case you want to disable telemetry during runtime.
87-
# ENV NEXT_TELEMETRY_DISABLED 1
101+
RUN addgroup --system --gid 1001 nodejs
102+
RUN adduser --system --uid 1001 nextjs
88103

89-
RUN addgroup --system --gid 1001 nodejs
90-
RUN adduser --system --uid 1001 nextjs
104+
# You only need to copy next.config.js if you are NOT using the default configuration
105+
# COPY --from=builder /app/next.config.js ./
106+
COPY --from=builder /app/public ./public
107+
COPY --from=builder /app/package.json ./package.json
91108

92-
# You only need to copy next.config.js if you are NOT using the default configuration
93-
# COPY --from=builder /app/next.config.js ./
94-
COPY --from=builder /app/public ./public
95-
COPY --from=builder /app/package.json ./package.json
109+
# Automatically leverage output traces to reduce image size
110+
# https://nextjs.org/docs/advanced-features/output-file-tracing
111+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
112+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
96113

97-
# Automatically leverage output traces to reduce image size
98-
# https://nextjs.org/docs/advanced-features/output-file-tracing
99-
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
100-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
114+
USER nextjs
101115

102-
USER nextjs
116+
EXPOSE 3000
103117

104-
EXPOSE 3000
118+
ENV PORT 3000
105119

106-
ENV PORT 3000
120+
CMD ["node", "server.js"]
121+
```
107122

108-
CMD ["node", "server.js"]
109-
```
123+
</details>
110124

111-
- You can now build an image to deploy yourself, or use a PaaS such as [Railway's](https://railway.app) automated [Dockerfile deployments](https://docs.railway.app/deploy/dockerfiles) to deploy your app.
125+
4. You can now build an image to deploy yourself, or use a PaaS such as [Railway's](https://railway.app) automated [Dockerfile deployments](https://docs.railway.app/deploy/dockerfiles) to deploy your app.
112126

113127
## Useful resources
114128

0 commit comments

Comments
 (0)