Some images become very big - one reason being that multiple RUN commands will create a layer and keep the data there. No removal.
Example:
RUN unzip myfile.war -d mynewdirectory/
RUN zip -r myfile.war mynewdirectory/
RUN mv myfile.war somedirectory
The myfile.war will be kept. It will not be deleted by the mv command.
Reason: Docker will create a layer for each RUN command.
Solution:
RUN unzip myfile.war -d mynewdirectory/ &&\
zip -r myfile.war mynewdirectory/ &&\
mv myfile.war somedirectory
Keep everything in one layer by utilizing concatenation with '&&\'.
WARNING:
Docker is highly optimized and based on Checksums.
If everything is concatenated, building an image can take very long.
Example: COPY or ADD will check wether a change in the underlying files or source code has been made and only execute if a change is detected.
Through concatenation, you reap Docker of the benefits regarding optimization (e.g. Checksums). No check. Everything is executed.
It is a good practice to keep this in mind when concatenating instrunctions.
Abonnieren
Kommentare zum Post (Atom)
NEW BLOG! http://cleancode.consulting/
Dear Reader, This Blog is closed and remains as an archive. Please find our new Blog at http://cleancode.consulting/
-
Resolve a Merge Conflict in GIT with IntelliJ Let us assume you are using Bitbucket or a similar tool to administrate and host your GI...
-
Just create a package-info.java file for your package in which you have your POJO: @javax.xml.bind.annotation.XmlSchema(namespace = ...
Keine Kommentare:
Kommentar veröffentlichen