-1

I have an error:

  File "/usr/local/lib/python3.6/site-packages/graphviz/backend.py", line 244, in pipe
    out, _ = run(cmd, input=data, capture_output=True, check=True, quiet=quiet)
  File "/usr/local/lib/python3.6/site-packages/graphviz/backend.py", line 167, in run
    raise ExecutableNotFound(cmd)
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpng'], make sure the Graphviz executables are on your systems' PATH

In my Mac when I do:

dot -V

I get:

dot - graphviz version 2.47.3 (20210619.1520)

and when I do:

which dot

I get:

/usr/local/bin/dot

It seems that docker doesn't recognise this package though. I tried to do:

$ export PATH="${PATH}:/usr/local/bin"

as explained in Where do I add Graphviz's Executable on a Mac but this doesn't solve the problem.

In the docker when I do:

pip install graphviz

It says:

Requirement already satisfied: graphviz in /usr/local/lib/python3.6/site-packages (0.15)

how can I make the docker recognise the executable? I can't do brew install graphviz inside the docker this command is accepted only in the Mac terminal but not in the docker.

Slava
  • 325
  • 5
  • 13
  • 1
    The container has its own separate filesystem and runtime environment; it can't use binaries installed on the host outside Docker (especially on a Mac where the host and container run different operating systems). You need to install the package in your image's Dockerfile, maybe using the Debian `apt-get` tool. – David Maze Jul 06 '21 at 14:27
  • @DavidMaze How can I do that for a docker that is running? – Slava Jul 06 '21 at 14:28
  • Build a new image, stop and delete the existing container, and `docker run` a new one from the updated images. – David Maze Jul 06 '21 at 14:37
  • @DavidMaze why can't I do that "on the fly" when the docker is running? – Slava Jul 06 '21 at 14:50
  • Because anything you change in the container filesystem will get lost as soon as the container exits; because you want to be able to check into source control the steps you need to do to build the image and container. Also, deleting and recreating a container is pretty cheap and there's no reason to avoid it. – David Maze Jul 06 '21 at 14:52
  • @DavidMaze I have no problem with that being gone after I finish the execution. (Similar to me doing pip install within the docker and not specifying it in advanced in the requirement.txt) – Slava Jul 06 '21 at 14:56

1 Answers1

2

I assume that at some point you have python installed in your docker container. In possession of this, you should have in your project a file called requirements.txt and inside it something like:

graphviz=~2.47.3

and your Dockerfile should look like this:

FROM python:3.8.6-slim

RUN apt-get update && apt-get -y install
RUN pip install --upgrade pip

WORKDIR /code
COPY /code
COPY requirements.txt .

RUN pip install -r requirements.txt

CMD ["python3", "<yourPythonScript>.py"]
EXPOSE 3000
COPY . .

To explain better, when your container is built, you should copy the requirements.txt file to the working directory of the docker container and then run the pip install -r requirements.txt command. This way, the graphviz package will be installed and accessible from its container.

Note: It's hard to understand without you showing us your Dockerfile.

Maykon Meneghel
  • 335
  • 6
  • 8
  • Sorry for wasn't clear. The docker is already running. I want to add the package for a specific ad hoc usage. so I used `docker exec -it id bash` and did `pip install graphviz` and just ran a specific script. The scripts runs fine on my Mac but doesn't work on the docker – Slava Jul 06 '21 at 14:25
  • Now I get it. Did you try to list the packages installed in this container? If your container is based on Alpine use this: `docker exec -i apk info -vv | sort`. If it is based on Debian & Ubuntu use this: `docker exec -i dpkg -l` – Maykon Meneghel Jul 06 '21 at 14:40
  • pip freeze shows the package is installed but I guess the binary is missing. `pip install graphviz` isn't enough for some reason I need also to run `brew install graphviz` to get the binary but I don't know how to do that on a running docker. – Slava Jul 06 '21 at 14:52
  • Well, I think the solution would be to install the package in your image's Dockerfile, just as you suggested @DavidMaze – Maykon Meneghel Jul 06 '21 at 15:02