简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM