Npm not found when running docker container from node image - node.js

# Dockerfile
FROM node:7-alpine
RUN mkdir -p /src/app
WORKDIR /src/app
COPY package.json /src/app/package.json
RUN npm install
COPY . /src/app
EXPOSE 3000
CMD ['npm', 'start']
I'm trying to complete a katacoda.com exercise for Dockerizing nodejs applications with the Dockerfile above. The build completes but running the image quits immediately and in the docker logs I see:
/bin/sh: [npm,: not found
I tried running the container in interactive mode with docker -it nodeapp /bin/bash which raised the error docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory". So I'm not sure what is going on here.

The reason it doesn't work is single quotes
CMD ['npm', 'start']
should be
CMD ["npm", "start"]
When you don't use double quotes, docker will remove the single quotes and process the command as [npm, start]
That is why you see error [npm, : not found

I had the same symptom but the problem was slightly different. Writing here in case google leads others in my situation to this link For me the issue was forgetting commas in the CMD. So the solution was going from CMD ["npm" "start"] to CMD ["npm", "start"].

Related

Docker Container exits upon running with "sh -c"

I am trying to run a webserver (right now still locally) out of a docker container. I am currently going step by step to understand the different parts.
Dockerfile:
FROM node:12.2.0-alpine as build
ENV environment development
WORKDIR /app
COPY . /app
RUN cd /app/client && yarn && yarn build
RUN cd /app/server && yarn
EXPOSE 5000
CMD ["sh", "-c","NODE_ENV=${environment}", "node", "server/server.js"]
Explanation:
I have the "sh", "-c" part in the CMD command due to the fact that without it I was getting this error:
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:346: starting container process caused "exec:
\"NODE_ENV=${environment}\": executable file not found in $PATH":
unknown.
Building the container:
Building the container works just fine with:
docker build -t auth_example .
It takes a little while since the build context is (even after excluding all the node_modules) roughly 37MB, but that's okay.
Running the container:
Running the container and the app inside works like a charm if I do:
MyZSH: docker run -it -p 5000:5000 auth_example /bin/sh
/app # NODE_ENV=development node server/server.js
However, when running the container via the CMD command like this:
MyZSH: docker run -p 5000:5000 auth_example
Nothing happens, no errors, no nothing. The logs are empty and a docker ps -a reveals that the container was exited right upon start. I did some googling and tried different combinations of -t -i -d but that didn't solve it either.
Can anybody shed some light on this or point me into the right direction?
The problem is you're passing three arguments to sh -c whereas you'd usually pass one (sh -c "... ... ...").
It's likely you don't need the sh -c invocation at all; use /usr/bin/env to alias that environment variable instead (or just directly pass in NODE_ENV instead of environment):
FROM node:12.2.0-alpine as build
ENV environment development
WORKDIR /app
COPY . /app
RUN cd /app/client && yarn && yarn build
RUN cd /app/server && yarn
EXPOSE 5000
CMD /usr/bin/env NODE_ENV=${environment} node server/server.js

starting container process caused "exec: \".\": executable file not found

i am new in docker. i want to deploy my application node js in docker but i am facing below error kindly help me this
/usr/bin/docker-current: Error response from daemon: oci runtime
error: container_linux.go:247: starting container process caused
"exec: \".\": executable file not found in $PATH".
docker build -t project_account_v1:1.1 .
docker container run -e TZ=Asia/Karachi -d -p 9191:9191 project_account_v1:1.1 .
Dockerfile:
FROM node:8.12
WORKDIR /app
COPY package.json /app
ENV NODE_ENV=production
RUN npm install
COPY . /app
VOLUME ["/app/logs"]
CMD ["node", "/app/app.js"]
EXPOSE 9191
"exec: \".\": executable file not found in $PATH".
Remove the . at the end of the Docker run command.

Docker: ENTRYPOINT can't execute command because it doesn't find the file

I'm trying to create a container from node js image and I have configured my Dockerfile as shown:
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app
RUN npm install
# Bundle app source
COPY . /usr/src/app
VOLUME ./:/usr/src/app
ENTRYPOINT [ "npm run watch" ]
In the package.json I have a script called watch than runs the gulp task named watch-less.
If I run npm run watch in my local environment the command works but when I try running the container it doesn't and shows the next error:
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"npm run watch\": executable file not found in $PATH".
ENTRYPOINT [ "npm run watch" ]
This is an incorrect json syntax, it's looking for the executable npm run watch, not the executable npm with parameters run and watch:
With the json syntax you need to separate each argument. You can use the shell syntax:
ENTRYPOINT npm run watch
Or you can update the json syntax like (assuming npm is installed in /usr/bin):
ENTRYPOINT [ "/usr/bin/npm", "run", "watch" ]
You also have an incorrect volume definition:
VOLUME ./:/usr/src/app
Dockerfiles cannot specify the how the volume is mounted to the host, only that an anonymous volume is defined at a specific directory location. With a syntax like:
VOLUME /usr/src/app
I've got strong opinions against using a volume definition inside of the Dockerfile described in this blog post. In short, you can define the volume better in a docker-compose.yml, all you can do with a Dockerfile is create anonymous volumes that you'd need to still redefine elsewhere if you want to be able to easily reuse them later.
If you use the list notation for ENTRYPOINT, that is, with the [brackets], you must separate the arguments properly.
ENTRYPOINT ["npm", "run", "watch"]
Right now it is trying to find a file literally named "npm run watch" and that does not exist.

Docker daemon unable to find the dockerfile

I am trying to create a node-js base image by using the following docker file
Dockerfile:
FROM node:0.10-onbuild
# replace this with your application's default port
EXPOSE 8888
I then run the command " sudo docker build -t nodejs-base-image ."
This keeps failing with the error
FATA[0000] The Dockerfile (Dockerfile) must be within the build context (.)
I am running the above command from the same directory where the 'Dockerfile' is located. What might be going on?
I am on Docker version 1.6.2, build 7c8fca2
This was happening because I did not have appropriate permissions to the Dockerfile in question

ASP.NET 5 and Docker error: /bin/sh: [dnx,: command not found

When I try to get a sample ASP.NET 5 beta5 application up and running on Docker, I am getting the following error on sudo docker start -a 2c1bec440dbc command:
/bin/sh: [dnx,: command not found
This is my docker file:
FROM microsoft/aspnet
COPY ./HelloWeb /app
WORKDIR /app
RUN ["dnu", "restore"]
EXPOSE 5004
ENTRYPOINT ["dnx", "." "web"]
The error message is kind of cryptic and I cannot seem to understand what is going wrong. The image has been built fine, packages has been restored nicely. Any idea?
It's a missing comma in the ENTRYPOINT line.
This leads docker to try running a ["dnx", command and passing "." "web"] as argument.
It should be
ENTRYPOINT ["dnx", ".", "web"]

Resources