I understand that each RUN command creates a layer. Suppose I have the following RUN commands:
RUN python -m pip install --upgrade pip
RUN python -m pip install --upgrade setuptools
RUN pip install -r requirements.txt
I wish to run all the command in one run command. Is the below OK to use?
RUN python -m pip install --upgrade pip; python -m pip install --upgrade setuptools; pip install -r requirements.txt
If I use the following, then it gives me an error "The token '&&' is not a valid statement separator in this version.":
RUN python -m pip install --upgrade pip && python -m pip install --upgrade setuptools && pip install -r requirements.txt
Yes you can and its a good practice
Instead of doing this
RUN python -m pip install --upgrade pip
RUN python -m pip install --upgrade setuptools
RUN pip install -r requirements.txt
Try this
RUN python -m pip install --upgrade pip &&\
python -m pip install --upgrade setuptools &&\
pip install -r requirements.txt
Advantages with that approach
Each instruction in the Dockerfile adds an extra layer to the docker image The number of instructions and layers should be kept to a minimum as it ultimately affects the build performance and time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With