That's a good question, it's yes and no, at least with docker
The default
python image is 885MB.
That's a lot! If you were just running
Code:
print("Hello World")
This would be a crazy amount of space.
Let's see how much space that takes (scroll right to see the whole output)
Code:
$ docker container run python python -c "print('hello world')"
hello world
$ docker ps -a --size
929797bb8f82 python "python -c 'print('h…" 17 seconds ago Exited (0) 16 seconds ago recursing_goldberg 157kB (virtual 885MB)
Ok, 885MB + 157KB
This means that when the container ran, it had a virtual size of 885MB and an actual size of 157KB.
Let's create 9 more for a even 10
Code:
$ for i in {1..9}; do docker container run python python -c "print('hello world')"; done
hello world # x9
$ docker ps -a --size
a8f733dffb92 python "python -c 'print('h…" 5 seconds ago Exited (0) 4 seconds ago elated_pare 157kB (virtual 885MB)
69368fa7f82e python "python -c 'print('h…" 6 seconds ago Exited (0) 5 seconds ago gracious_perlman 157kB (virtual 885MB)
ddcfc455799f python "python -c 'print('h…" 6 seconds ago Exited (0) 5 seconds ago peaceful_galileo 157kB (virtual 885MB)
34fb4c3beb7b python "python -c 'print('h…" 7 seconds ago Exited (0) 6 seconds ago tender_edison 157kB (virtual 885MB)
a41ed1a612bf python "python -c 'print('h…" 7 seconds ago Exited (0) 6 seconds ago charming_galileo 157kB (virtual 885MB)
2aca072f58bc python "python -c 'print('h…" 8 seconds ago Exited (0) 7 seconds ago upbeat_tharp 157kB (virtual 885MB)
7a79147f19bf python "python -c 'print('h…" 8 seconds ago Exited (0) 7 seconds ago condescending_hopper 157kB (virtual 885MB)
e3ba41e952d4 python "python -c 'print('h…" 9 seconds ago Exited (0) 8 seconds ago elated_kapitsa 157kB (virtual 885MB)
bd14d06bedd7 python "python -c 'print('h…" 9 seconds ago Exited (0) 9 seconds ago compassionate_archimedes 157kB (virtual 885MB)
929797bb8f82 python "python -c 'print('h…" 2 minutes ago Exited (0) 2 minutes ago recursing_goldberg 157kB (virtual 885MB)
Here's the big question.
Are we using 8.5GB + 1.57MB, or are we using 885MB + 1.57MB?
Any one of those containers can use anything in that huge image, but if you check, the file size used is only 886.57MB
So yes, they each separately have their own house with a couch food etc.. But in a sense they're sharing the same house too and only take the space of a single house.