Skip to content Skip to sidebar Skip to footer

Build A Docker Volume Based Of An Image

Im trying to build a docker volume directly from a JS image through a bash command. The difficulty here mostly lays on the fact that I want the contents of the volume to be the ev

Solution 1:

From my understanding you can proceed like this:

1) create a docker image that contains everything is needed to run the js file (OS, node etc)

2) once you receive the js file, create a temporary directory on the local drive and copy that file to it

3) run the container, mount your local dir and tell the container to execute the file from there. The command can look like this

docker run \
   --mount type=bind,src=/your-temp-dir,dst=/temp-dir,readonly \
   --detach \
   your-docker-image-name \
   node /temp-dir/your-javascript-file.js

See https://docs.docker.com/engine/reference/run/ for more details.

Solution 2:

I am not sure if you really need to dockerize the JS file. Rather what you can do is write the incoming stream (which is JS) to another file e.g. volume-creator.js and then call that file.

In this case your volume-creator.js should also include dependencies like node-docker which will make your docker commands easy and OS agnostic.

The reason I would avoid dockerizing the invoker JS is you may need some extra privileges to run docker commands within the container e.g you may need to mount the docker socket which can make your host OS and docker system vulnerable .

Post a Comment for "Build A Docker Volume Based Of An Image"