-
Notifications
You must be signed in to change notification settings - Fork 397
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
Can't build on docker. #86
Comments
when I do |
I used env variables via process.env and when use |
https://zeit.co/docs/v2/build-step#using-environment-variables-and-secrets environment variables for build time needs |
I recently encountered this problem too. I'm deploying to a bare metal Kubernetes cluster, not Zeit/Vercel, so I don't have the option of creating environment variables there (if I understand @huang47 correctly). I cheated and created a .env.staging file which I copy to .env as part of my Docker build for my staging environment. When I get to production, I'll need a .env.production, meaning I end up with Docker images for staging and production. Not ideal, but it solves the immediate problem. |
I've noticed something that may be useful. I'm deploying to a Kubernetes cluster, and as long as the relevant environment variables are present and correct in the application deployment, they'll override whatever was in the .env file used during the build. So, you can just copy your dev .env file (or some template) into the Docker build to get you through the build stage without the error, and then when you run the container, the environment variables set in the environment will take precedence. My Dockerfile looks like this: FROM node:14.4.0-stretch as builder
WORKDIR /app
COPY src .
COPY next.config.js .
COPY package.json .
COPY .env.template .env
RUN yarn install
RUN yarn build
FROM node:14.4.0-stretch
WORKDIR /app
COPY --from=builder /app .
EXPOSE 3000
CMD ["node_modules/.bin/next", "start"] My .env.template file looks like this:
And I mean actually like that. Those aren't dummy values for the purpose of posting on Github - that's what's actually in the file (and it's checked into source control so my CI build just works as well). The point is that it gets through the Docker build. These values will never be actually used because they'll all be set in the environment (and actually, if they're not set, the app won't work and won't pass smoke tests so will alert me to missing values). My Kubernetes deployment looks something like this: spec:
containers:
- image: registry.gitlab.com/myaccount/myproject/mynextclient:latest
imagePullPolicy: Always
name: web-client
ports:
- containerPort: 3000
env:
- name: AUTH0_CLIENT_ID
value: 'l2wMlA2sxAs697kaZ1pWkpA5UHODwsNj'
- name: AUTH0_DOMAIN
value: 'mydomain.eu.auth0.com' In this example, mydomain.eu.auth0.com is a dummy value for posting this answer. The actual value is my Auth0 domain. If you're running the image through Docker, I assume you could just pas the correct environment variables through the command line, or in the environment section of a Compose file. I expect there's a more correct way of doing this, but it works for my purposes. I hope it's of some help. |
The way I used the dummy env is a good idea. |
I found a solution that worked for my case (I'm deploying it using caprover). Add the build and the start to the Dockerfile CMD:
|
I think this looks good. |
Closing this in favour of #154 - see #154 (comment) |
@tomclark How do you exactly set the AUTH0_BASE_URL under your k8s deployment? |
Description
When doing a docker build, an error occurs because there is no environment variable in the
next build
.I want to
next build
without env.Environment
The text was updated successfully, but these errors were encountered: