简体   繁体   中英

How to pass arguments to the python script that is running inside docker container?

I'm running python script inside docker container. Depending on the passed parameters my script should show different information. I want to pass this parameter trough the docker run {my_image_name} {parameters} command, where instead {parameters} i want to type some custom values that my script expects to receive. Found some info about arguments and env variables, but don`t understand it. Can anybody explain how to do it resolving my issue? What should i add to dockerfile? Dockerfile content:

FROM python:3.8.2-buster
WORKDIR /usr/src/app
COPY metrics.py .
RUN pip install --upgrade pip
RUN python -m pip install psutil
CMD python /usr/src/app/metrics.py

When i'm running docker run {my_image_name} {my_script_name} {parameter} i'm getting:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"metrics.py\": executable file not found in $PATH": unknown.

I work on windows.

You are missing ENTRYPOINT

Docker file should be something like this:

FROM python:3.8.2-buster
WORKDIR /usr/src/app
COPY metrics.py .
RUN pip install --upgrade pip
RUN python -m pip install psutil
ENTRYPOINT ["python"]
CMD ["/usr/src/app/metrics.py"]

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