Rule of two

9
Rule of Two Rich Moyse 2/22/2017

Transcript of Rule of two

Page 1: Rule of two

Rule of Two

Rich Moyse 2/22/2017

Page 2: Rule of two

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

Page 3: Rule of two

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

Page 4: Rule of two

“…neither can live while the other survives!”

Page 5: Rule of two

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?

Page 6: Rule of two

“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…

Page 7: Rule of two

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

Page 8: Rule of two

Build Friendly Runtime Friendly

docker buld --squash

Page 9: Rule of two

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.