Wazbat
Wazbat6d ago

permission denied error when running deno install inside dockerfile

Hi there, I'm in the process of trying to migrate my node app to deno, as I was really impressed with the recent deno 2 announcement I have the following dockerfile, slightly modified from the example.
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

# Prefer not to run as root.
USER deno

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

# 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

# Prefer not to run as root.
USER deno

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

# 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"]
However when trying to build this, I get an error when running the deno install step:
1.753 error: Failed caching npm package 'lodash.mapvalues@4.6.0'.
1.753
1.753 Caused by:
1.753 Permission denied (os error 13)
1.753 error: Failed caching npm package 'lodash.mapvalues@4.6.0'.
1.753
1.753 Caused by:
1.753 Permission denied (os error 13)
The package listed is random. Previously it was ky, before that it was logform. I'm at a loss, as deno install works fine on my windows machine
2 Replies
Wazbat
Wazbat6d ago
I thought the error was caused by the ENV DENO_DIR=./.deno_cache that I added due to the following: https://github.com/denoland/deno_docker/blob/main/README.md#running-on-google-cloud-rungcr However even after removing it I still get that same os error, now due to failing to write the lockfile:
0.910 Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
0.910 ┠─ npm:protobufjs@7.4.0
0.910 ┃
0.910 ┠─ This may cause the packages to not work correctly.
0.910 ┠─ Lifecycle scripts are only supported when using a `node_modules` directory.
0.910 ┠─ Enable it in your deno config file:
0.910 ┖─ "nodeModulesDir": "auto"
1.065 error: Failed writing lockfile.
1.065
1.065 Caused by:
1.065 Permission denied (os error 13) (for '/app/deno.lock')
0.910 Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
0.910 ┠─ npm:protobufjs@7.4.0
0.910 ┃
0.910 ┠─ This may cause the packages to not work correctly.
0.910 ┠─ Lifecycle scripts are only supported when using a `node_modules` directory.
0.910 ┠─ Enable it in your deno config file:
0.910 ┖─ "nodeModulesDir": "auto"
1.065 error: Failed writing lockfile.
1.065
1.065 Caused by:
1.065 Permission denied (os error 13) (for '/app/deno.lock')
I'm at a loss
coty
coty5d ago
Seems like the deno user doesn’t have permissions in /app. Also seems like your lockfile is outdated, it shouldn’t be trying to write (there are flags that alter that behavior also)