Skip to content

Add pnpm/nodejs support #8

@gsangeryee

Description

@gsangeryee

In some project, we need to run pnpm install to install dependencies.
However, when running the command inside a dev container, we encounter a permission denied error.

I am new to Docker and tried setting up the environment based on your files.

devcontainer.json

// added runArgs
"runArgs": [
        // Read only filesystem except for explicitly writable volumes (check mounts)
        // For a dev environment this is more a hussle than a feature.
        // "--read-only",
        "--tmpfs=/tmp:rw,noexec,nosuid,size=512m",
        "--tmpfs=/var/tmp:rw,noexec,nosuid,size=512m",
        "--tmpfs=/dev/shm:rw,noexec,nosuid,size=64m",
        // Drop all capabilities
        "--cap-drop=ALL",

        // A few security additions (AppArmor & no new privileges)
        "--security-opt", "no-new-privileges",
        "--security-opt", "apparmor:docker-default",

        // Use seccomp's default 
        // "--security-opt", "seccomp=default",


        // Play a little bit with resources.
        // "--memory=512m",
        // "--cpus=2"
    ],

    // Writable mounts in case you want to set --read-only above.
    "mounts": [
    ],

Dockerfile

...
# Set HOME
ENV HOME=/home/vscode

# Set needed paths (for python, pix, pnpm)
ENV USR_LOCAL_BIN=/usr/local/bin
ENV LOCAL_BIN=${HOME}/.local/bin
ENV PNPM_HOME=${HOME}/.local/share/pnpm
ENV PATH=${PATH}:${USR_LOCAL_BIN}:${LOCAL_BIN}:${PNPM_HOME}

USER root
## Install nvm, yarn, npm, pnpm
RUN curl -o- https://raw.githubusercontent.com/devcontainers/features/main/src/node/install.sh | bash
RUN chown -R vscode:vscode ${HOME}/.npm
USER vscode

Here is an example:

Example:
Command

pnpnpm install --frozen-lockfile

Error:

Error: spawnSync /workspace/musd/node_modules/.pnpm/[email protected]/node_modules/esbuild... EACCES

Is there a safe and recommended way to fix this issue?
Any suggestions would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions