DEV Community

Discussion on: Wait for MongoDB, Postgres or MySql to start on Docker

Collapse
 
kferrone profile image
Kelly Ferrone

Hey thanks its a nice one. I just want to tweak a bit your Dockerfile to make the image smaller and cleaner. Check this out:

FROM node:latest

RUN mkdir /src

WORKDIR /src
ADD app/package.json /src/package.json

## THE LIFE SAVER
RUN npm install && \
    curl -L https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait \
    -o ./node_modules/.bin/wait && \
    chmod +x ./node_modules/.bin/wait

EXPOSE 3000

ENTRYPOINT [ "npm" ]

## Launch the wait tool and then your application
CMD [ "run", "start:docker" ]

in your package.json scripts make a script like so

"start:docker": "wait && npm start"

Any executable in the node_modules/.bin folder is automatically added to your path when running thorugh npm. Enjoy!