0

I'm trying to figure why Nodemon is not restarting from within docker when passing in an environment variable. It worked previously when I was not trying pass in an env variable and instead in my Dockerfile the final command was CMD ["npm", "run", "devNoClient"]

I can see Nodemon launching in the terminal but doesn't restart the server when I update a file.

Makefile

node_dev:
    echo 'Starting Node dev server in Docker Container'
    docker build -t node_dev .
    docker run -it --env-file variables.env -p 8080:8080 node_dev


Dockerfile

WORKDIR /chord-app
# copy package.json into the container
COPY package.json /chord-app/
# install dependencies
RUN npm install
# Copy the current directory contents into the container at /chord-app
COPY . /chord-app/
# Make port 8080 available to the world outside this container
EXPOSE 8080
# Env is required to persist variable into built image.
# Docker run can now accept variable and it will be assigned here.
# default is run in dev mode
ENV run_mode_env=devNoClient
# Run the app when the container launches
# Due to variable, CMD syntax must change for this to work https://stackoverflow.com/a/40454758
CMD npm run $run_mode_env


package.json
"scripts": {
  "devNoClient": "nodemon --exec babel-node src/server/start.js",
},
Anton Emery
  • 87
  • 1
  • 4
  • 9

1 Answers1

1

I realized it was not working because I don't have any binding volumes to my local machine when starting my docker image. So the container does not what files on my machine to watch for saves so it can restart the server with nodemon.

Anton Emery
  • 87
  • 1
  • 4
  • 9