0

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?

pymat
  • 1,090
  • 1
  • 23
  • 45
  • Does this answer your question? [Is it ok to run docker from inside docker?](https://stackoverflow.com/questions/27879713/is-it-ok-to-run-docker-from-inside-docker) – Akihito KIRISAKI Dec 27 '20 at 11:51
  • @AkihitoKIRISAKI: reading this article it basically says don't do it – pymat Dec 27 '20 at 12:03
  • You need to install the `docker` binary. However, you need to be very careful with basic security concerns, like shell-injection attacks: If I set `path = "/:/host' busybox cat /host/etc/shadow; : '`, that will print out the host's encrypted-password file instead of running the tool you show, and I'm well on my way to rooting the host. – David Maze Dec 27 '20 at 12:32

1 Answers1

1

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

  • Although I do not like the idea of running docker inside docker container, +1 for this answer in python context as it is apt for the OP's query. – Sandeep Dec 27 '20 at 13:32