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'
Related
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
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.
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.
When I start my docker container with:
docker run -it -d -p 8081:8080 --name ${APP_CONTAINER_NAME} ${APP_IMAGE}
I can access my web application just fine in my browser on: localhost:8081
But if I instead run it with the two volumes below:
docker run -it -d -p 8081:8080 -v ${PWD}:/app -v /app/node_modules --name ${APP_CONTAINER_NAME} ${APP_IMAGE}
The port mapping is ignored - I cannot access it at localhost:8081 but I can access it at localhost:8080.
My dockerfile has:
FROM node:8-alpine
RUN apk update && apk add bash
RUN npm install -g http-server
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8080
CMD [ "http-server", "dist" ]
Why does adding the volumes to the second docker run command ignore the port mapping from 8081 to 8080?
As suggested below running without -d (but with volumes):
docker run -it -p 8081:8080 -v ${PWD}:/app -v /app/node_modules --name ${APP_CONTAINER_NAME} ${APP_IMAGE}
gives:
Starting up http-server, serving dist
Available on:
http://127.0.0.1:8080
http://172.17.0.2:8080
Hit CTRL-C to stop the server
But I cannot access it on localhost:8080 or localhost:8081 even though the container is indeed running:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
603b1bf02d58 app-image "http-server dist" 11 seconds ago Up 5 seconds 0.0.0.0:8081->8080/tcp app-container
When I instead run it without volumes but still map to 8081 it works:
Starting up http-server, serving dist
Available on:
http://127.0.0.1:8080
http://172.17.0.2:8080
Hit CTRL-C to stop the server
and I can access it on localhost:8081. So something in the application must be messed up when adding the volumes just not sure what. I have also tried to run:
docker volume prune
before starting the container but it has no effect. Any ideas why creating the volumes prevents the application from being accessed?
I'm having problems configuring docker for my nodejs app.
I have previously set up containers for both php and rails with port forwarding working flawlessly, but for this instance i can't seem to get it to work.
Running: docker ps, i get the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a60f9c82d600 29c7d94a8c58 "/bin/sh -c 'npm s..." 5 seconds ago Up 3 seconds 3000/tcp romantic_albattani
As you can see I'm not getting the usual: 0.0.0.0:3000->3000/tcp that I am expecting.
docker-compose ps gives:
Name Command State Ports
------------------------------
My docker-compose.yml:
web:
build: .
volumes:
- .:/app
volumes_from:
- box
ports:
- "3000:3000"
box:
image: busybox
volumes:
- /node_modules
My Docker file:
FROM node:8.7.0
# The base node image sets a very verbose log level.
ENV NPM_CONFIG_LOGLEVEL warn
WORKDIR /tmp
COPY package.json /tmp/
RUN npm install
WORKDIR /app
ADD . /app
RUN cp -a /tmp/node_modules /app/
#ENV PORT=3000
EXPOSE 3000
CMD npm start
I'm running the command: docker-compose up --build
Any help at this point is appreciated.
I don't know if a docker inspect would be useful, but if so, tell me and i will also post it.
Edit: Changed my Dockerfile to follow the answer.
Your docker-compose.yml file has bad formatting, since you are not getting any errors i will assume you pasted it here wrong, here is the version with the fixed indenting:
web:
build: .
volumes:
- .:/app
volumes_from:
- box
ports:
- "3000:3000"
box:
image: busybox
volumes:
- /node_modules
Your Dockerfile has a bug, you are missing the ENTRYPOINT and/or CMD stanzas, instead you are using the RUN stanza with the wrong intent, here is a working Dockerfile with the fix applied:
FROM node:8.7.0
# The base node image sets a very verbose log level.
ENV NPM_CONFIG_LOGLEVEL warn
WORKDIR /tmp
COPY package.json /tmp/
RUN npm install
WORKDIR /app
ADD . /app
RUN cp -a /tmp/node_modules /app/
#ENV PORT=3000
EXPOSE 3000
CMD npm start
Your Dockerfile halted the execution of docker-compose at the docker image building stage because of the RUN npm start which is a process that starts and listens until stopped (because you want it to start your node app and listen for connections) causing docker-compose to never finish the docker image creating step, let alone the other steps like creating the needed containers and finish the entire docker-compose runtime process.
In short:
When you use RUN it is meant to run a command do some work and return sometime to continue the building process, it should return and exit code of 0 and the process will move on to the next Dockerfile stanza, or return another exit code and the building process will fail with an error.
When you use CMD you tell the docker image what is the starting command of all the containers started from this image (it can also be overridden at run time with docker run). It is tightly related to the ENTRYPOINT stanza, but for basic usage you are safe with the default.
Further reading: ENTRYPOINT, CMD and RUN