pymat
pymat

Reputation: 1192

Calling Docker command within Dockerized app

It's been asked before but I haven't been able to find the answer so far. I have a script which is called via a Flask app. It's Dockerized and I used docker-compose.yml. The docker command, which worked outside of Docker, creates a html file using openscad. As you can see below, it takes a variable path:

    cmd_args = f"docker run -v '{path}':/documents/ --rm --name manual-asciidoc-to-html " \
               f"asciidoctor/docker-asciidoctor asciidoctor -D /documents *.adoc"

    Popen(cmd_args, shell=True)
    time.sleep(1)

When the script executes, the print out in Terminal shows:

myapp    | /bin/sh: 1: docker: not found

How can I get this docker command to run in my already running docker container?

Upvotes: 0

Views: 113

Answers (1)

user10170559
user10170559

Reputation:

I don’t really get what you are trying to say here but I‘m assuming you want to run the docker command from within your container. You don’t really do it that way. The way to communicate with the docker daemon from within a container is to add the Docker Unix socket from the host system to the container using the -v when starting the container or adding it to the volumes section of your docker-compose:

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

After doing that you should be able to use a docker API (https://github.com/docker/docker-py) to connect to the Daemon from within the container and do the actions you want to. You should be able to convert the command you initially wanted to execute to simple docker API calls.

Regards Dominik

Upvotes: 1

Related Questions