Home > Enterprise >  Docker run nodejs script on a remote server and store output files in a host system
Docker run nodejs script on a remote server and store output files in a host system

Time:01-31

I have a Docker container on which I would like to a run a nodejs application.

The application is just a script reading files and generating csv files. There is no frontend and therefore it does not need to run on a port. Command to run nodejs application.

node index.js --flag_a <flag_a_name> --flag_b <flag_b_name>

How to configure a Dockerfile so I can run the script in a container and store the output outside the container (in a host system).

** My Dockerfile content **

FROM node:12-alpine
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
ENTRYPOINT ["node index.js", "--flag_a flag_a_name", "--flag_b flag_b_name"]

I have already installed docker, nodejs and npm.

CodePudding user response:

In order to use arbitrary command line arguments - just pass them to docker run.

Minimal example:

// index.js
console.log(process.argv);
# Dockerfile

FROM node:14-alpine
WORKDIR /app
COPY index.js .
ENTRYPOINT ["node", "/app/index.js"]
 docker build -t somename .
docker run somename --a=2 --b=2
[ '/usr/local/bin/node', '/app/index.js', '--a=2', '--b=2' ]

In order to save data to the host machine from a Docker container - the easiest, and probably preferred way is using

Docker volumes

CodePudding user response:

You can use docker volumes

Docker volumes ref1 Docker volumes ref2

  •  Tags:  
  • Related