Change default run command of VSC Docker extension - node.js

When right-clicking on an image in Microsoft's Docker plugin and selecting run it executes the following command:
docker run --rm -d -p 3000:3000/tcp falaen:latest
I would like it to run the following command instead:
docker run --restart=always -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -p 3000:3000 -d falaen
I have tried to modify the run command in the Dockerfile but without success.
Of course, I can run the command manually in the terminal each time but it would be nicer to simply right click on the image and then run it.

You could try adding this line to your VSCode's settings.json, to override the default configuration of the command.
"docker.commands.run": "docker run --restart=always -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -p 3000:3000 -d ${tag}"
This will run the command using any image you select.

Related

How to know which node:alpine image version is in running container

I have one running container which uses node:alpine as base image.I want to know version of this image.
You can check the Dockerfile of the container if handy.
You can check the first line with FROM node:<version>-alpine
For example :
FROM node:12.18.1-alpine
ENV NODE_ENV=production
WORKDIR /app
You can also use the command docker image inspect
https://docs.docker.com/engine/reference/commandline/image_inspect/
You can also exec into the container to check the version of Node
Command to check node version:
docker exec -ti <Container name> sh -c "node --version"
Try running the command FROM node:<version>-alpine
You can also try running the command alpine -v or alpine -version .You can also start Alpine and press? on the main menu to open the main Help page, which will also tell you the version.
Refer to the link for more information.

How to get back to shell in nodejs:latest docker image?

I'm newbie to docker, I tried this command
docker run -it node:latest
then, I was in the node REPL,
Welcome to Node.js v16.3.0.
Type ".help" for more information.
>
I tried control+c ,but this quit the image,
Is there any way to go to the shell in this image?
In order to overwrite the entry point of the docker image you're using, you will need to use the --entrypoint flag in the run command.
docker run -it --entrypoint bash node:latest
For better understanding on how to work with already running docker container you can refer to the following question

Running commands for docker container

This is how I'm running a command in a docker container:
$ docker run -it --rm --name myapp myimage:latest
$ node --version
Is it possible to to run this as one command? Can I pass a command to the docker run-command?
Something like
$ docker run -it --rm --name myapp myimage:latest "node --version"
Of course this is just a simple example. Later I will execute some more complex commands...
The "docker run" command essentially will make the container run, and execute the "CMD" or "ENTRYPOINT" in the Dockerfile. Unless - the command in your dockerfile does not run a command prompt - "running" the container may not get you the prompt.
For example if you want that everytime you run the container - it gets you the command prompt then have the line below in your Dockerfile.:
CMD ["bash"]
If you want to run the same commands everytime you run the command - then you could create a script file with your commands, copy them to the container, and execute the script file as a CMD directive.
The general form of the command is actually:
docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
See documentation for more details.
The answer to the minimal example in your question is simply:
docker run -it --rm --name myapp myimage:latest node --version
If you want to run multiple commands in sequence, you can:
Run container
Execute your commands against the running container using docker exec
Remove it
I am having some trouble understanding what you are trying to do.
you can just :
docker run -d --name myapp myimage:latest -f /dev/null and then your container is up and you can run any command in it
you can pass a command to the docker run but once the command ends the container will exit

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