简体   繁体   中英

Docker container generates docker containers on is host

I have a node js server that generates docker containers. I want to put that node js server on a docker container but if I do that the server will generate the containers inside it's container.

How can I do for the server generate the containers on the host?

The Docker daemon from you host machine listens on /var/run/docker.sock .
If you mount that socket in a docker container, basically the docker commands executed inside the container will be sent to the docker daemon from your host.

A simple example is to run a container form the docker image and play around:

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

// Create a new container from the container
# docker run alpine

// List the containers running on the host, from the container:
docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
b6f70442d667        alpine              "/bin/sh"                3 seconds ago       Exited (0) 2 seconds ago                       nifty_sinoussi
0cd034af9ebc        docker              "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes                                   determined_raman

Note that the dummy alpine container was created on the host machine. Exit the docker container and check for the alpine container on the host machine:

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
b6f70442d667        alpine              "/bin/sh"                2 minutes ago       Exited (0) 2 minutes ago                       nifty_sinoussi
0cd034af9ebc        docker              "docker-entrypoint.s…"   11 minutes ago      Exited (0) 3 seconds ago                       determined_raman

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM