How to get version of node from docker container? - node.js

To get a node version - I expect to run the following:
node --version
I'm running the following with docker:
docker run node:4-onbuild -v
I get this:
docker: Error response from daemon: Container command '--version' not found or does not exist..
My question is: How to get version of node from docker container?

you need to specifically ask docker to run -v within the node container like below
docker run -it --rm node /bin/bash -c 'node --version'

Related

Run docker command into node container

I have a nodejs application inside a docker containter, and I'm trying to run another docker image from the container.
I connected the docker socket to the container, ran the machine, and I went into the containter.
docker run -it -v /var/run/docker.sock:/var/run/docker.sock -w /root node bash
When I write in the terminal docker I get an error:
bash: docker: command not found.
It happens precisely in the specific image of NodeJS, if for example I run such a test
docker run -v /var/run/docker.sock:/var/run/docker.sock \
-ti docker
It works great.
Why can't I run docker in the node image?
This not work because to mount sockets nodejs container must include a docker instance inside it.
Just try another general image other than docker. It also will not work. Search for nodejs images it self include docker. Use that then it will work.
If such image not exist you have to create new image from both docker and nodejs images and add command to start it.

install node packages without restarting docker compose

Is there a way to install node packages in a running docker environment without restarting?
I have running a few containers via docker-compose and need to use npm i <packagename> while the containers are running.
So far, I have found no consistent answer to google.
docker exec -it [container-id] /bin/bash
cd to the workspace and npm install packagename . Should install the package you want and also add it in package.json
Use docker exec + npm install <package-name>.
https://docs.docker.com/engine/reference/commandline/exec/
You can run any command in an active container using docker exec. In your case it will be:
// Replace <your-container-id> and <your-package-name>
docker exec -it <your-container-id> "npm install <your-package-name>"
or if you want to use a container name instead of a container id you can use:
// Replace <your-container-id> and <your-package-name>
docker exec -it $(docker ps | grep <your-container-name> | awk '{ print $1 }') "npm install <your-package-name>"
Here you have more informations about the docker exec docker exec command. (Docker Docs)

how to test an aws lambda function using docker

I am trying to test a simple lambda function using docker on windows.
I already have a docker lambcy/lambda image
But this line:
docker run --rm -v "$PWD":/var/task lambci/lambda
does not work on windows.
What is the appropiate way to do this?
docker run --rm -v "$PWD":/var/task lambci/lambda
The command that you running is targeting linux platform, as for windows platform maybe you can try below instead
docker run --rm -it -v %cd%:/var/task lambci/lambda

Cannot start Spark in Docker container

I'm trying to run a Spark instance using Docker (on Windows) following this explanation: https://github.com/sequenceiq/docker-spark
I was able to:
Pull the image
Build the image
I had to download the Github repository with the Dockerfile though and specify that in the build command. So instead of docker build --rm -t sequenceiq/spark:1.6.0 . I had to run docker build --rm -t sequenceiq/spark:1.6.0 /path/to/dockerfile
However when I try to run the following command to run the container:
docker run -it -p 8088:8088 -p 8042:8042 -p 4040:4040 -h san
dbox sequenceiq/spark:1.6.0
I get the error:
Error response from daemon: Container command '/etc/bootstrap.sh' not found or does not exist.
I tried copying the bootstrap.sh file from the Github repository to the /etc directory on the VM but that didn't help.
I'm not sure what went wrong, any advice would be more than welcome!
It is probably an issue with the build context because you changed the path to the Dockerfile in your build command.
Instead of changing the path to the Dockerfile in the build command, try cd'ing into that directory first and then running the command. Like so:
cd /path/to/dockerfile
docker build --rm -t sequenceiq/spark:1.6.0 .

Docker image for sailsjs development on macosx hangs

I have a docker image build on Arch Linux (sailsjs-dev) with node and sailsjs which I would like to use for development, mounting the app directory inside the container as follows:
docker run --rm --name testapp -p 1337:1337 -v $PWD:/app \
sailsjs-dev sails lift
$PWD is the directory with the sails project.
This works fine on linux, but if I try to run it on macosx (with docker-machine) it hangs forever at the very beginning, with log level set on silly (in config/log.js):
info: Starting app...
There is no other output, this is all we get.
Note, the same docker image works perfectly also on mac with an express app. What could be peculiar of sail that causes the problem?
I can also add that on a mac docker uses a virtualbox instance named docker machine.
We solved it running npm install from within the docker container:
docker run --rm --name testapp -p 1337:1337 -ti -v $PWD:/app \
sailsjs-dev /bin/bash
npm install --no-bin-links
--no-bin-links avoids the creation of symlinks.

Resources