Docker in Docker

Motivation

  • Can containers run inside other containers?
    YES!
  • Is there a use case for such a case?
    Well, one famous one is the ability to run Kubernetes cluster in a single machine, using containers.
    This is what the minikube software is doing
  • If you run jenkins inside containers, it may be usefullAS well.
  • In the next section we'll explore containers inside containers.

Docker in Docker

  • Here's a demo:
    • (we are using the --priviledged of docker run, as it is needed for this feature)
    • We are running the containers as a detached, then run a shell inside it
 1osboxes@osboxes:~$ docker run -d --privileged  docker:dind 
 2915ae36a28de1fb0d5ca276fe591ac23359a5d9bc5e72f01faf6b31fd31f6018
 3osboxes@osboxes:~$ docker exec -it quirky_herschel  sh
 4/ # ps -e
 5PID   USER     TIME  COMMAND
 6    1 root      0:00 docker-init -- dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2376 --tlsverify --tlscace
 7   56 root      0:17 dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2376 --tlsverify --tlscacert /certs/serve
 8   65 root      0:00 containerd --config /var/run/docker/containerd/containerd.toml
 9  395 root      0:00 sh
10  400 root      0:00 ps -e
11/ # 
12/ # 
13/ # docker pull python:3.8
143.8: Pulling from library/python
15Digest: sha256:6ea16099cac9f66419d1fc3a63aaa9d783214e8e38d2a1c0db2bfb0852ef9b7d
16Status: Image is up to date for python:3.8
17docker.io/library/python:3.8
18/ # 
19/ # docker images
20REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
21python       3.8       17b8b8dc7004   5 weeks ago   996MB
22/ # 
23/ # docker run -it python:3.8
24Python 3.8.19 (default, Apr 24 2024, 13:04:15) 
25[GCC 12.2.0] on linux
26Type "help", "copyright", "credits" or "license" for more information.
27>>> 
28>>> print('This is python!!!')
29This is python!!!
30>>> 
31/ # exit
32osboxes@osboxes:~$