install nodejs during a docker image creation

118 Views Asked by At

i have an issue while trying to create my first docker image.

here is my docker file:

FROM debian:9

RUN apt-get update -yq \
    && apt-get install -yq curl gnupg \
    && curl -sL https://deb.nodesource.com/setup_10.x | bash \
    && apt-get install -yq nodejs \
    && apt-get clean

ADD . /app/
WORKDIR /app
RUN npm install

EXPOSE 2368
VOLUME /app/logs

CMD npm run start

i do have a package.json file with all dependancies in my folder but i still have this error as a response:

ERROR: failed to solve: process "/bin/sh -c apt-get update      && apt-get install curl gnupg     && curl -sL https://deb.nodesource.com/setup_10.x | bash     && apt-get install -y nodejs     && apt-get clean" did not complete successfully: exit code: 100
1

There are 1 best solutions below

0
On BEST ANSWER

To fix the issue, you can make the following modifications to your Dockerfile:

# Use an official Node.js runtime as the base image
FROM node:10

# Create a directory
WORKDIR /app

# Copy the package.json and package-lock.json files into the container
COPY package*.json ./

# Install your application's dependencies
RUN npm install

# Copy the rest of your application code into the container
COPY . .

# Expose the port
EXPOSE 2368

# Define the command to run your application
CMD npm start