I have a very simple Node.js app that takes in a location as a command line argument (const location = process.argv[2];) and logs the weather of that location to the console. I'm trying to run it in a docker container just to get practice with docker.
Here is the Dockerfile:
FROM node:10
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
ENV location=San\ Diego
CMD ["sh", "-c", "node app.js ${location}"]
The problem is, I can't pass in an environment variable that is more than one word. For example, San Diego gets run as just San. This is the case with both the default environment variable in the Dockerfile and any environment variables I pass it when I run the image.
How can I make it so that I can pass in something like Los Angeles and have the app fetch the data for Los Angeles, for both the ENV variable in the Dockerfile, as well as any environment variable passed in as an arg when I run the image?
ENV location="San Diego"work?node app.js ${location}". You should be able to access the envvar in app.js via process.envprocess.env.locationexists, then set location to that variable, otherwise, set location toprocess.argv[2]so that it can also run locally.