2
votes

I am trying to run my docker image, but I am receiving the following error:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"python3\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled

Here is my Dockerfile:

FROM python:3.6-alpine3.7

RUN apk add --no-cache python3-dev \
    && pip3 install --upgrade pip

RUN apk add --no-cache --update \
    python3 python3-dev gcc \
    gfortran musl-dev

RUN apk add --no-cache libressl-dev musl-dev libffi-dev

RUN python3.6 -m pip install --upgrade pip

RUN apk --no-cache add git

RUN apk add mariadb-dev

WORKDIR /socialworks-api

COPY . /socialworks-api

RUN pip3 --no-cache-dir install -r requirements.txt

ENV PATH="/opt/gtk/bin:$env/development.env"

EXPOSE 5000

ENTRYPOINT ["python3"]
CMD ["app.py"]

I think the issue might be with the ENV PATH which I set. I have also tried setting it to:

ENV PATH="/opt/gtk/bin:${env/development.env}"

But I would receive the following error when building my dockerfile:

Step 11/14 : ENV PATH="/opt/gtk/bin:${env/development.env}"
failed to process "\"/opt/gtk/bin:${env/development.env}\"": missing ':' in substitution

Without setting the environment, my application won't run.

I have also tried running on my dockerfile this command:

RUN export $(grep -v '^#' ./env/development.env | xargs)

It build successfully, but when I enter this command to the terminal:

docker run -it flaskapp

I am receiving an error that it still unable to locate the env variables.

$ docker run -it flaskapp
Traceback (most recent call last):
  File "app.py", line 11, in <module>
    app.config.from_object("config.Config")
  File "/usr/local/lib/python3.6/site-packages/flask/config.py", line 174, in from_object
    obj = import_string(obj)
  File "/usr/local/lib/python3.6/site-packages/werkzeug/utils.py", line 568, in import_string
    __import__(import_name)
  File "/socialworks-api/config.py", line 4, in <module>
    class Config(object):
  File "/socialworks-api/config.py", line 5, in Config
    MYSQL_HOST = os.environ['MYSQL_HOST']
  File "/usr/local/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'MYSQL_HOST'
1
Yes, your $PATH setting removes all of the system directories like /bin and /usr/bin. Make sure to include the existing $PATH in the variable value. - David Maze
Thank you for your answer. Could you please specify what command should I run in my dockerfile? Because my full environment path is socialworks-api/env/development.env and my workdir is socialworks-api, I think it should be enough for env/development.env. - Dave

1 Answers

2
votes

In your Dockerfile you specify

ENV PATH="/opt/gtk/bin:$env/development.env"

When you later run python3, the system looks in only these two directories, and when there's not a Python there, you get the error you see. It's probably in /usr/bin/python3, but the directory /usr/bin isn't in $PATH.

The simplest answer here is to delete this line entirely. Your Dockerfile creates neither a /opt/gtk nor a /development.env directory, so there's no files in either path that could be executed. If you do need to install custom software, putting it in a directory that's in the default system path (like /usr/local/bin) is a good approach.

If you do need to keep this line, make sure the existing $PATH stays as part of the value.

ENV PATH="/opt/gtk/bin:$PATH"

(Don't specify ENTRYPOINT ["python"]; combine this into a single CMD ["python3", "app.py"]. I'd encourage you to run docker run --rm -it yourimage /bin/sh to look around the filesystem and run debugging commands like env, but the ENTRYPOINT declaration breaks this use, and having the script file named in the CMD means it's still not the "container-as-command" pattern.)