0

Is there a way to install any application inside docker container , only when it has not been installed before?

For example;

RUN apt-get install -y nginx

Will install nginx everytime on a new rebuild. How would one check if nginx already exists? If not install else just update or do nothing. Is this possible somehow? I have good reasons to need nginx inside another container for now getting things up and running lateron could move to seperating nginx to own container.

Rubytastic
  • 223
  • 1
  • 2
  • 14

1 Answers1

2

By default, Docker will save each your build step. So, whenever you re-build your image, Docker will check the its cache and use the cache if you do same thing in the same state.

As @jordanm said, yum and apt-get also will check the app already installed or not. So, if you do yum install nginx twice, it will not re-install the nginx (as long as you don't tell the yum or apt-get to reinstall nginx).

jordanm
  • 889
  • 5
  • 9
Edward Samuel
  • 791
  • 7
  • 9