Claudiu Creanga
Claudiu Creanga

Reputation: 8366

Run command on entrypoint in docker outputs no file errors

On a simple dockerfile:

FROM python:3
ENV PYTHONUNBUFFERED 1
WORKDIR /code/

If I run:

docker build -t my_image .
docker run -v ~/Downloads/data/:/home -it -d my_image # mount data folder inside home
docker exec -it container_id  sh -c  "python script.py -i /home/db.sqlite"

Everything runs ok. But I would like to run the script.py on run so that there is no need for an exec command.

So I added to the dockerfile:

ENTRYPOINT ["python script.py -i /home/db.sqlite"]

But when I run my container now it fails with a file or folder not found error at python script.py

Upvotes: 0

Views: 47

Answers (1)

Mattias Wadman
Mattias Wadman

Reputation: 11425

I think the problem is how the ENTRYPOINT syntax works. Your using the exec-form and it does not find the binary (it uses the whole command line as path to the binary).

From https://docs.docker.com/engine/reference/builder/#entrypoint:

ENTRYPOINT has two forms:
ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
ENTRYPOINT command param1 param2 (shell form)

So try either:

ENTRYPOINT ["/path/to/python", "script.py", "-i", "/home/db.sqlite"]

Or

ENTRYPOINT python script.py -i /home/db.sqlite

Upvotes: 1

Related Questions