Alpit Anand
Alpit Anand

Reputation: 1248

Docker container throwing error on running it

I have been learning docker for now, i made a docker file which is like this.

FROM node:10

# Create app directory
WORKDIR /app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json /app/

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
ADD ./* /app/

EXPOSE 8080
CMD [ "npm", "start" ]

And my file directory looks like this,

enter image description here

My server is working fine with my local machine, however, when running with docker container it's throwing an error. The error is: enter image description here

Can someone help me with it ?

Upvotes: 0

Views: 906

Answers (2)

Daniel Klischies
Daniel Klischies

Reputation: 1135

ADD ./* /app/ does not what you probably think it does. It matches all files that satisfy ./* according to Go's filepath match (docs) and copies them to /app/. For details, see this answer.

What you should do instead is add . /app/ or add . . (which are equivalent, because you changed the workdir to /app). That recurisvely copies the contents of your current directory into the container fileysystem, maintaining the directory structure.

Upvotes: 1

Sagar Chilukuri
Sagar Chilukuri

Reputation: 1448

Update the Dockerfile to the following and try:

FROM node:10

# Create app directory
WORKDIR /app/

# RUN apt-get update && apt-get install -y --no-install-recommends nano

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

# RUN npm install
# If you are building your code for production
RUN npm install --only=production

COPY . .

CMD ["node", "server.js"]

EXPOSE 8080

When you set WORKDIR to /app/, the current directory is updated. So there no need to mention /app during copy.

Upvotes: 1

Related Questions