Nat! bio photo

Nat!

Senior Mull.

Twitter RSS

Github

A little experiment to understand docker image inheritance

This test creates three small containers from these four files.

a/Dockerfile
b/Dockerfile
c/Dockerfile
run.sh

a/Dockerfile (for image mulle/a)

FROM debian:latest

COPY a /a

b/Dockerfile (for image mulle/b)

FROM mulle/a

COPY b /b

c/Dockerfile (for image mulle/c)

FROM mulle/b

COPY b /b
COPY c /c

run.sh (creates images and data files and runs the containers)

#!/bin/bash

docker rmi mulle/c 2> /dev/null
docker rmi mulle/b 2> /dev/null
docker rmi mulle/a 2> /dev/null

echo "a" > a/a
echo "b" > b/b
echo "c (was b)" > c/b
echo "c" > c/c

docker build -q -t mulle/a a
docker build -q -t mulle/b b
docker build -q -t mulle/c c 

# if any run fails, the container won't be reaped by --rm INCONVENIENT

docker run --rm mulle/a /bin/cat /a
docker run --rm mulle/b /bin/cat /a
docker run --rm mulle/b /bin/cat /b
docker run --rm mulle/c /bin/cat /a
docker run --rm mulle/c /bin/cat /b
docker run --rm mulle/c /bin/cat /c

echo "x" > a/a
docker build -q -t mulle/a a

docker run --rm mulle/a /bin/cat /a
docker run --rm mulle/b /bin/cat /a
docker run --rm mulle/c /bin/cat /a

docker rmi mulle/c
docker rmi mulle/b
docker rmi mulle/a

The output will be

a
a
b
a
c (was b)
c

and after rebuilding mulle/a with the contents of /a changed to 'x'

x
a
a

Summary

Images once created and inherited can not be changed. One needs to rebuild all the containers to propagate changes. (At least at my current level of understanding)


1 Comment

A photo of Andrei Ismail

From: Andrei Ismail

Thanks, very insightful!

Post a comment

All comments are held for moderation; basic HTML formatting accepted.

Name:
E-mail: (not published)
Website: