Search code examples
node.jslaraveldockernginxyarnpkg

How can i install the yarn package in an nginx:1.25 container


I have containerized my laravel project. However, I want to be able to run yarn commands on the web container(nginx:1.25 container). I have searched the internet, but haven't had success finding an answer.

This is my Dockerfile

FROM nginx:1.25

# Copy the Nginx configuration file
COPY ./default.conf /etc/nginx/conf.d/default.conf

# Add yarn here

# Set the working directory
WORKDIR /src

Solution

  • It differs from the base image you are using, for your case, nginx:1.25 is based on debian bookworm, so I recommend installing yarn using nvm and npm:

    FROM nginx:1.25
    
    # Copy the Nginx configuration file
    COPY ./default.conf /etc/nginx/conf.d/default.conf
    
    # Add yarn here
    RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash \
        && source ~/.bashrc \
        && nvm install --lts \
        && npm install -g yarn
    
    
    # Set the working directory
    WORKDIR /src