Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker: npm install on docker start

I'd like to have some kind of "development docker image" in which npm install is executed every time I restart my Docker Container (becuase I don't want to build, push and pull the new dev image every day from my local machine to our Docker server). So I thought I could do sth. like this in my Dockerfile:

CMD npm install git+ssh://[email protected]/my/project.git#develop && npm start

Sadly, this doesn't work. The container stops immediately after docker start and I don't know why, because this works:

RUN npm install git+ssh://[email protected]/my/project.git#develop
CMD npm start

(Just for testing, that's of course not what I want to have). But maybe I have some wrong perception of CMD and someone could enlighten me?

like image 703
Munchkin Avatar asked Jul 15 '26 07:07

Munchkin


1 Answers

Make your CMD point to a shell script.

CMD ["/my/path/to/entrypoint.sh"]

with that script being:

#!/bin/bash
npm install git+ssh://[email protected]/my/project.git#develop
npm start
# whatever else

I find this easier for a few reasons:

  1. Inevitably these commands increase with more being done
  2. It makes it much easier to run containers interactively, as you can run them with docker run mycontainer /bin/bash and then execute your shell script manually. This is helpful in debugging
like image 54
enderland Avatar answered Jul 17 '26 15:07

enderland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!