0

I want to run the booksServer first, then the customersServer, then fire main.js

But before firing off main.js I want to make sure that customersServer and booksServer are running first.

How do I do this properly?

Here's my dockerfile now

FROM node:12.14.0
WORKDIR /usr/src/app
COPY package*.json ./
COPY . /usr/src/app
RUN npm install
RUN npm install nodemon -g
EXPOSE 4555
CMD nodemon /books/booksServer.js && nodemon /customers/customersServer.js && node /main/main.js

I know usually you want to separate containers for multiple processes, but I was having gRPC issues when doing this... So I want to try it as a single dockerfile for now.

TheRoadLessTaken
  • 531
  • 2
  • 7
  • 15
  • I think you'll be better off running 3 containers and instead try to fix gRPC/network issues. `docker-compose` works great for running multiple containers in local development. – Christian Fosli Jul 31 '20 at 19:57
  • Agreed, I've decided to do that. I'm currently trying to use wait-for-it (https://github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh) so that the main service waits for the servers to spin up. A bit confused with wait-for-it but looking through some articles – TheRoadLessTaken Jul 31 '20 at 20:13
  • 1
    What about as a workaround, sleep between the commands? `nodemon a.js & sleep 10 && node.....` – Sergio Santiago Jul 31 '20 at 21:03
  • I guess my question was is this a valid CMD? CMD nodemon /books/booksServer.js && nodemon /customers/customersServer.js && node /main/main.js – TheRoadLessTaken Jul 31 '20 at 21:15
  • It looks valid according to [the docs](https://docs.docker.com/engine/reference/builder/#cmd) – Christian Fosli Jul 31 '20 at 21:27

1 Answers1

0

Assuming booksServer.js and customersServer.js are offering ports for communication you could use this script. The script is commonly used to wait for another service to be ready to used.