Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more updated docker instructions #354

Merged
merged 5 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/template/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Please note that Next.js requires a different process for buildtime (available i
});
```

2. Remove the `env`-import from [next.config.mjs](./next.config.mjs):
2. Remove the `env`-import from [next.config.mjs](./template/base/next.config.mjs):
Copy link
Member

@juliusmarminge juliusmarminge Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old link was correct here

Copy link
Member

@juliusmarminge juliusmarminge Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the suggestions, but when I think of it, we could merge steps 1 and 2? Using diff-mode makes that quite handy, what'ya a think?

- import { env } from "./src/env/server.mjs";

  ...

  export default defineNextConfig({
    ...
+   output: "standalone",
  });

juliusmarminge marked this conversation as resolved.
Show resolved Hide resolved

```diff
- import { env } from "./src/env/server.mjs";
Expand Down Expand Up @@ -90,7 +90,7 @@ Please note that Next.js requires a different process for buildtime (available i
# Install dependencies only when needed
# TODO: re-evaluate if emulation is still necessary on arm64 after moving to node 18
FROM --platform=linux/amd64 node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/ b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

Expand Down
22 changes: 17 additions & 5 deletions www/src/pages/en/deployment/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ layout: ../../../layouts/mainLayout.astro

You can containerize this stack and deploy it as a single container using Docker, or as a part of a group of containers using docker-compose.

Please note that Next.js requires a different process for buildtime (available in the frontend, prefixed by `NEXT_PUBLIC`) and runtime environment variables. In this demo we are using two variables, `NEXT_PUBLIC_FOO` and `BAR`. Pay attention to their positions in the `Dockerfile`, command-line arguments, and `docker-compose.yml`.
Please note that Next.js requires a different process for buildtime (available in the frontend, prefixed by `NEXT_PUBLIC`) and runtime environment, server-side only, variables. In this demo we are using two variables, `NEXT_PUBLIC_FOO` and `BAR`. Pay attention to their positions in the `Dockerfile`, command-line arguments, and `docker-compose.yml`.

## Docker

1. In your [next.config.mjs](./next.config.mjs), add the `output: "standalone"` option to your config.
1. In your [next.config.mjs](https://github.com/t3-oss/create-t3-app/blob/main/cli/template/base/next.config.mjs), add the `standalone` output-option to your config:

2. Delete the first line (`import { env } from "./src/env/server.mjs";`) from [next.config.mjs](./next.config.mjs).
```diff
export default defineNextConfig({
reactStrictMode: true,
swcMinify: true,
+ output: "standalone",
});
```

2. Remove the `env`-import from [next.config.mjs](https://github.com/t3-oss/create-t3-app/blob/main/cli/template/base/next.config.mjs):

```diff
- import { env } from "./src/env/server.mjs";
```

3. Create a `.dockerignore` file with the following contents:
<details>
Expand Down Expand Up @@ -43,7 +55,7 @@ Please note that Next.js requires a different process for buildtime (available i
# Install dependencies only when needed
# TODO: re-evaluate if emulation is still necessary on arm64 after moving to node 18
FROM --platform=linux/amd64 node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/ b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

Expand Down Expand Up @@ -122,7 +134,7 @@ Please note that Next.js requires a different process for buildtime (available i

5. To build and run this image locally, run:

```
```bash
docker build -t ct3a -e NEXT_PUBLIC_FOO=foo .
docker run -p 3000:3000 -e BAR="bar" ct3a
```
Expand Down