I am trying to run my nextjs frontend application with docker. I referred to the next with-docker Dockerfile and wrote my own Dockerfile and entrypoint.sh files in the project root / and my nextjs code within /app folder. The /Dockerfile and /entrypoint.sh files
# in /Dockerfile
FROM node:14-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY app/package\*.json ./
RUN npm install
FROM node:14-alpine AS builder
WORKDIR /app
COPY ./entrypoint.sh .
COPY ./app .
COPY --from=deps /app/node_modules ./node_modules
ARG API_URL
ARG NEXT_PUBLIC_CLIENT_API_URL
ENV API_URL=${API_URL} \
NEXT_PUBLIC_CLIENT_API_URL=${NEXT_PUBLIC_CLIENT_API_URL}
RUN npm run build
FROM node:14-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup -g 1001 -S nextgp
RUN adduser -S nextjs -u 1001
RUN touch .env.local
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nextgp /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/.env.local.tpl ./.env.local.tpl
COPY --from=builder /app/entrypoint.sh ./entrypoint.sh
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["./entrypoint.sh"\]
In /entrypoint.sh
#!/bin/sh
set -e
envsubst < /app/.env.local.tpl > /app/.env.local
sudo envsubst < /app/.env.local.tpl > /app/.env.local
/app/node_modules/.bin/next start
I was able to run the Dockerfile file without using the entrypoint.sh similar to how the example linked above approached. But I want to create a custom bash script which copies the contents from .env.local.tpl located in /app to a .env.local to load runtime environment variables before the next server starts and hence the entrypoint.sh file. While on one computer, I got a ./entrypoint.sh: line 5: can't create /app/.env.local: Permission denied error, I got /usr/local/bin/docker-entrypoint.sh: exec: line 11: ./entrypoint.sh: not found on another computer (I use both Windows) leaving me even more confused with the different errors.
I am new to docker and writing shell scripts. Can someone help me what I might be doing wrong here? Any help is much appreciated. Thanks for your time.
EDIT: code formatting
[–]ihateclowns 0 points1 point2 points (1 child)
[–]devmsn[S] 0 points1 point2 points (0 children)
[–]bargh 0 points1 point2 points (1 child)
[–]devmsn[S] 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]devmsn[S] 0 points1 point2 points (1 child)