sylvie
sylvie
DDeno
Created by Wazbat on 10/27/2024 in #help
permission denied error when running deno install inside dockerfile
sorry to revive an old thing- found this via questions.deno.com somehow and figured i'd share the answer to help others: this is a docker problem. deno install in docker is trying to write to a root level directory, which needs root access. however, since you have USER deno above the RUN deno install line, it is trying to install packages as a non-root user, which will fail. The fix is to move USER deno to after RUN deno install:
FROM denoland/deno:2.0.3
# set DENO_DIR to avoid conflicts with google cloud
ENV DENO_DIR=./.deno_cache
ENV NODE_ENV=production

WORKDIR /app

COPY deno.json .
COPY deno.lock .
RUN deno install

# Prefer not to run as root.
USER deno

# These steps will be re-run upon each file change in your working directory:
COPY . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache src/index.ts

ENV PORT=8080
EXPOSE $PORT

CMD ["run", "--allow-all", "src/index.ts"]
FROM denoland/deno:2.0.3
# set DENO_DIR to avoid conflicts with google cloud
ENV DENO_DIR=./.deno_cache
ENV NODE_ENV=production

WORKDIR /app

COPY deno.json .
COPY deno.lock .
RUN deno install

# Prefer not to run as root.
USER deno

# These steps will be re-run upon each file change in your working directory:
COPY . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache src/index.ts

ENV PORT=8080
EXPOSE $PORT

CMD ["run", "--allow-all", "src/index.ts"]
5 replies