-1

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.

Murlidhar Fichadia
  • 2,589
  • 6
  • 43
  • 93
  • Do you actually need Docker here? One of the goals of Docker (intentionally) is that it's hard to read and write host files; if you only need this one script and a Node installation, can you just copy it to the remote system and run it? A general-purpose system automation tool like Ansible, Chef, or Salt Stack might help this. – David Maze Jan 31 '22 at 14:03
  • Also see [How to mount a host directory in a Docker container](https://stackoverflow.com/questions/23439126/how-to-mount-a-host-directory-in-a-docker-container) which discusses ways to get around Docker's filesystem isolation. There is nothing you can configure in the Dockerfile itself to allow this. – David Maze Jan 31 '22 at 14:06

1 Answers1

0

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

madflow
  • 7,718
  • 3
  • 39
  • 54