Rule of two
-
Upload
rich-moyse -
Category
Technology
-
view
11 -
download
1
Transcript of Rule of two
Rule of Two
Rich Moyse 2/22/2017
Concerns: Build vs Runtime
1. FROM debian:jessie # ==> Install build tools...
2. RUN apt-get update
3. RUN apt-get install -y make gcc # ==> Compile, and install...
4. COPY . /buildContext WORKDIR /buildContext/redis
5. RUN make
6. RUN make install # ==> Clean up...
7. RUN apt-get remove -y --auto-remove make gcc
8. RUN apt-get clean
9. RUN rm -rf /var/lib/apt/lists/* /buildContext # ==> Execute… WORKDIR / ENTRYPOINT ["redis-server"]
1. FROM debian:jessie2. COPY . /buildContext3. RUN apt-get update \
&& apt-get install -y make gcc \ # ==> Compile, and install... && cd /buildContext/redis \ && make \ && make install \ # ==> Clean up... && apt-get remove -y --auto-remove make gcc \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /buildContext \ # ==> Execute… WORKDIR / ENTRYPOINT ["redis-server"]
Build Friendly Runtime Friendly
Build Friendly Runtime Friendly
1. FROM debian:jessie
1. 1.
2. RUN apt-get update
3. RUN apt-get install –y …
4. COPY . /buildContext
5. RUN make
6. RUN make install
7. RUN apt-get remove …
8. RUN apt-get clean 9. RUN rm -rf /../lists/* … 3. 2,3,5-9
2. 4
“…neither can live while the other survives!”
docker build --squash• Long History: #332 - 4/2013, #3116 - 12/2013, #6906 -7/2014,
#12198 - 4/2015, …• Pull request #22641:• Merges N physical layers into single one.• Eliminates logically deleted files.
• How to decide which layers to preserve?
“Always two there are, no more, no less.”Runtime Friendly = Microservice
Service Service ServiceService Service ServiceService Service ServiceService Service Service
Application
Dependencies
.
.
. Dependency Layer
Service Layer
Service layer
Depend layer
Service layer
Depend layer
Service layer
Depend layer
Service layer
Depend layer
Service layer
Depend layer
Service layer
Depend layer
Service layer
Depend layer
Service layer
Depend layer
Application…
Build Friendly Runtime Friendly
1. FROM debian:jessie
1. 1.
2. RUN apt-get update
3. RUN apt-get install –y …
4. COPY . /buildContext
5. RUN make
6. RUN make install
7. RUN apt-get remove …
8. RUN apt-get clean 9. RUN rm -rf /../lists/* … 2-9
docker build --squash
Build Friendly Runtime Friendly
docker buld --squash
Summary• A runtime image (microservice) consists of only 2 logical layers.
• --squash option can enforce “Rule of 2”.
• Although experimental, --squash will almost certainly be publically available in next release.
• Future Dockerfile features will hopefully obsolesce --squash.