run docker from another docker

12/3/2019

suppose we have 4 different images that exist in our system with these names:

container_1

container_2

container_3

container_4

suppose we run container_1 . my question is: is that possible container_1 run remains containers like container_2? I searched and questions and article I found was: docker runs in another docker? but this is not my case I need to run other containers alongside container_1.sry my knowledge about dockers is little.

-- babak abadkheir
docker
kubernetes

2 Answers

12/3/2019

If you want to run another container inside an already running container, then yes, you need to do "docker run" inside that container.

Just treat the container as if it was your laptop. In your laptop, if you want to start a container, you use docker run right? Same thing if you were inside a running container.

Running a container inside another container is ill-advised though, as it posses many security risks. Mainly because you need to assign privileges on the host machine to allow the user of the container to gain access to the docker engine, but doing so also exposes your host machine directory and file system into the running container.

I'd take a look at : Is it ok to run docker from inside docker?

-- alex067
Source: StackOverflow

12/3/2019

first you should use the host docker socket, then execute "docker run" from container_1. so add this:

-v /var/run/docker.sock:/var/run/docker.sock

when run container_1.

-- hossein bazrafkan
Source: StackOverflow