Issue with docker permissions - node.js

I just learning about docker Volumes.
I have this code aside Node.js project.
this is my Docker file:
FROM node:14
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 80
VOLUME [ "./app.feedback" ]
CMD ["node", "server.js"]
and this is my command
docker run -d -p 3000:80 --rm --name feedback-app -v feedback:/app/feedback -v "C:\Users\amit\personal\data-volumes-01-starting-setup:/app" -v /app/node_modules feedback-node:volumes
and this is the error
OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/var/lib/docker/volumes/ebfb2e17b5bf6768527c205789667de5ca31b29b9a9603297b7fbc2881c95701/_data" to rootfs at "/app/node_modules" caused: mkdir /var/lib/docker/overlay2/87136c8400ec6a42517fb51eb41084c6a6e5825f877addb7dea71af167a7a43d/merged/app/node_modules: permission denied: unknown.
PS C:\Users\amit\personal\data-volumes-01-starting-setup>

Use this base image instead:
FROM node:lts-alpine

Related

Cannot run docker image argon2 invalid ELF header

My dockerfile:
FROM node:14
WORKDIR /app
COPY package.json .
RUN npm install
COPY . ./
EXPOSE 3000
CMD ["node", "./bin/www"]
First I run docker run -p 3000:3000 -d --name node-app node-app-image
It gives me a hash
Then I run docker ps to check running container which is empty
Then I run docker ps -a It gives me this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b5a2deea8bd node-app-image "docker-entrypoint.s…" 4 minutes ago Exited (1) 4 minutes ago node-app
there was exception in log: return process.dlopen(module, path.toNamespacedPath(filename)); Error: /app/node_modules/argon2/lib/binding/napi-v3/argon2.node: invalid ELF header at Object. (/app/node_modules/argon2/argon2.js:9:56) code: 'ERR_DLOPEN_FAILED'

Nodejs Serverless Docker Image

I am trying to setup a docker image for my local serverless development and I'm having issues reaching the files using volumes.
Dockerfile
FROM node:8.10
ADD . /code
WORKDIR /code
RUN npm install -g serverless
RUN npm install serverless-offline
EXPOSE 3000
# COPY . /code
CMD ["serverless", "offline", "--host", "0.0.0.0", "--port", "5000"]
docker-compose-yml
version: "3"
services:
serverless_proj_1:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:5000"
volumes:
- .:/code
- /code/node_modules
Docker is listening to all my serverless endpoints correctly:
But when i'm triggering one of the api endpoints from Postman this is the error I'm getting:
docker container exec apps-services_serverless_proj_1_1
pwd returns /code
docker container exec apps-services_serverless_proj_1_1 ls -al returns my codebase
docker container exec apps-services_serverless_proj_1_1 ls /code -al again returns my codebase(both commands have same total)
docker container exec apps-services_serverless_proj_1_1 ls /code/node_modules -al returns all my dependencies(total 3074)
I don't see an RUN npm install. since you are marking a place holder for the node_modules you will need to install them inside the container.
EDIT
Please try attaching to your running docker container and looking in the node_modules folder. Just to double check that a) you have one, b) it is located where it should be and c) it contains all the modules you expect.
You can do this by running docker container exec -it serverless_proj_1 /bin/bash this should put you in the /code dir by default, then just run ls -al

Why files/folders are created with different ownership in docker run as root?

Could you explain why this happens?
When I have such Dockerfile:
FROM node:12
WORKDIR /app
CMD ["touch", "somefile"]
I execute:
sudo docker build -t test1 .
sudo docker run -it --mount type=/my_folder,dst=/app test1
I get somefile created by root user.
When I have such Dockerfile:
FROM node:12
WORKDIR /app
CMD ["npm", "install"]
I execute(the same as above):
sudo docker build -t test1 .
sudo docker run -it --mount type=/my_folder,dst=/app test1
I get node_modules created by non-root user
Why do I get different users for created files in both cases? Isn't is supposed to be root user?

npm install package through running node container

I've followed the steps in the node.js documentation for creating a Dockerfile. I'm trying to run the command docker exec -it mynodeapp /bin/bash in order to go inside the container and install a new package via npm, but I get the following error
OCI runtime exec failed: exec failed: container_linux.go:346: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown
Any ideas what I'm doing wrong?
for ref this is how my docker-compose and dockerfile look like
FROM node:latest
RUN mkdir /app
WORKDIR /app
RUN npm install -g nodemon
COPY package.json package.json
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
and
version: '3'
services:
nodejs:
container_name: mynodeapp
build: .
command: nodemon --inspect server.js
ports:
- '5000:8080'
volumes:
- '.:/app'
networks:
- appnet
networks:
appnet:
driver: 'bridge'
Change docker exec mynodeapp -it /bin/bash to docker exec -it mynodeapp /bin/sh
According to docker documentation the correct syntax is the following:
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
-i and -t are the options
mynodeapp is CONTAINER
/bin/bash - is
a COMMAND inside container
And another problem is that there is no bash shell inside container, so you can use sh shell.

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.

Resources