I'm in a planning phase for a little tool for myself. I have to say that I have close to 0 experience with docker.

My setup

  • 1 x Nodejs App in a Container (lets call it App)
  • n x Instances/Containers of the same image (lets call it Agent)

What I want

I'm looking for a way to restart one of the Agents from within my App.

The problem
I just managed to create my first docker-compose. From here I'm stuck. I just have no idea how to cross-access the container from my Apps container (by script) or if this is even possible and then force to restart it (like docker restart #hash does).

My current docker-compose.yml (if that helps in any way)

version: '3'
        container_name: app
            - .:/usr/src/app
        restart: always
        build: .
            - '8080:3000'
            - agent

    # no control over this as this is an existing image from docker hub
        restart: always
        image: image/from/dockerhub
            - '1234'

... which I would run as docker-compose up --scale agent=n.

I'm not necessarily looking for a complete solution. If someone could guide me into the right direction I would really appreciate it.


  • What's the IP address of containers? And, how you implemented the networking section?
    – M. Rostami
    Apr 29, 2020 at 17:02
  • What do you mean which IP address? Its virtual. Which networking section? I've got nothing more than in the question.
    – C4d
    Apr 29, 2020 at 19:09

2 Answers 2


In majority of circumstances I wouldn't recommend this in production, but to restart docker container from another container, you need to install docker in that container and then run that "master" container with

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

as described here: https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/ (look for "The solution" part of the article).

But check your architecture and see if you really need to restart one container from another or if there is some other way.

  • (Remember that any entity that can get access to the host's Docker socket can pretty trivially root the host. Be extra careful around basic security issues, and especially when you're making Docker-related calls.)
    – David Maze
    Apr 30, 2020 at 10:41

You can open a socket to have the docker command available inside a container:


But...even if technically possible docker experts suggest to not do because of security reasons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.