I want to create a docker container which contains one or more containers. Is it possible with Docker?
Asked
Active
Viewed 1.1k times
8
-
Why would you do that ? Are you going to implement in a Docker container a new type of container ? In my opinion Docker is not designed for this purpose but is rather a platform for developers enabling portability and compatibility with others applications. – Ko2r Dec 31 '14 at 12:42
-
I have 4 containers, each depends on one another. I want to create an image by adding only one(the most dependent) container. So, what I expect is, like, for ex: A,B,C,D are containers. dependency goes like this, A->B->C->D. I want to only include D & so the rest can be done automatically. – Dec 31 '14 at 12:47
-
Hum I'm getting it ! I don't think it's a good practice because if you're able to do that then included containers (A,B,C in D if I'm right) will not be accessible from other containers ... And you are loosing the sharing principle of Docker, aren't you ? Why don't you wanna pack 4 containers and deploy them in a Docker instance, you really need only one image ? – Ko2r Dec 31 '14 at 13:23
1 Answers
22
To run docker inside docker is definitely possible. The main thing is that you run
the outer container with extra privileges (starting with --privileged=true
) and then install docker in that container.
Check this blog post for more info: Docker-in-Docker.
One potential use case for this is described in this entry. The blog describes how to build docker containers within a Jenkins docker container.
However, Docker inside Docker it is not the recommended approach to solve this type of problems. Instead, the recommended approach is to create "sibling" containers as described in this post

wassgren
- 18,651
- 6
- 63
- 77
-
2FYI you do not need all the steps in that tutorial anymore. Just run your container as ```--privileged=true``` and then run ```apt-get install docker.io``` inside your container. – Usman Ismail Dec 31 '14 at 15:58
-
1@UsmanIsmail - Excellent, thank you! It was I while since I did Docker-in-Docker. – wassgren Dec 31 '14 at 16:00
-
"sibling" containers could lead to orphans in a way that nested containers cannot. Am I right? See https://stackoverflow.com/q/47084681/14731. – Gili Nov 07 '17 at 16:37
-