0

I have a simple code that checks if a docker container by a specific name is running inside a machine and (if not) send out SMS.

def is_running(container_name):
    try:
        container = DOCKER_CLIENT.containers.get(container_name)
        container_state = container.attrs['State']
        container_is_running = container_state['Status'] == RUNNING
        return container_is_running
    except Exception as _:
        return False

I want to run this application inside another docker container. How do I check if another docker container is running from inside a docker container?

  • Your container will need access to the Docker socket so you'll need to map that into the container as a volume mount if that works on your target OS. – tadman Jul 18 '22 at 02:54
  • @tadman not sure I understand. –  Jul 18 '22 at 04:11
  • 1
    When you start the container, you need to `docker run -v /var/run/docker.sock:/var/run/docker.sock` to get access to the host's Docker daemon. Note that, if you have this access, you can almost trivially use it to root the entire host, so consider carefully whether this is something you _need_ to do. – David Maze Jul 18 '22 at 11:09

0 Answers0