I built a docker image using Dockerfile with Python and some libraries inside (no my project code inside). In my local work dir, there are some scripts to be run on the docker. So, here what I did
$ cd /path/to/my_workdir
$ docker run -it --name test -v `pwd`:`pwd` -w `pwd` my/code:test python src/main.py --config=test --results-dir=/home/me/Results
The command python src/main.py --config=test --results-dir=/home/me/Results is what I want to run inside the Docker container.
However, it returns,
/home/docker/miniconda3/bin/python: /home/docker/miniconda3/bin/python: cannot execute binary file
How can I fix it and run my code?
Here is my Dockerfile
FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04
MAINTAINER Me <[email protected]>
RUN apt update -yq && \
apt install -yq curl wget unzip git vim cmake sudo
RUN adduser --disabled-password --gecos '' docker && \
adduser docker sudo && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER docker
WORKDIR /home/docker/
RUN chmod a+rwx /home/docker/ && \
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
bash Miniconda3-latest-Linux-x86_64.sh -b && rm Miniconda3-latest-Linux-x86_64.sh
ENV PATH /home/docker/miniconda3/bin:$PATH
Run pip install absl-py==0.5.0 atomicwrites==1.2.1 attrs==18.2.0 certifi==2018年8月24日 chardet==3.0.4 cycler==0.10.0 docopt==0.6.2 enum34==1.1.6 future==0.16.0 idna==2.7 imageio==2.4.1 jsonpickle==1.2 kiwisolver==1.0.1 matplotlib==3.0.0 mock==2.0.0 more-itertools==4.3.0 mpyq==0.2.5 munch==2.3.2 numpy==1.15.2 pathlib2==2.3.2 pbr==4.3.0 Pillow==5.3.0 pluggy==0.7.1 portpicker==1.2.0 probscale==0.2.3 protobuf==3.6.1 py==1.6.0 pygame==1.9.4 pyparsing==2.2.2 pysc2==3.0.0 pytest==3.8.2 python-dateutil==2.7.3 PyYAML==3.13 requests==2.19.1 s2clientprotocol==4.10.1.75800.0 sacred==0.8.1 scipy==1.1.0 six==1.11.0 sk-video==1.1.10 snakeviz==1.0.0 tensorboard-logger==0.1.0 torch==0.4.1 torchvision==0.2.1 tornado==5.1.1 urllib3==1.23
USER docker
ENTRYPOINT ["/bin/bash"]
asked Jul 6, 2020 at 9:33
GoingMyWay
17.6k33 gold badges105 silver badges153 bronze badges
2 Answers 2
Try making the file executable before running it.
as John mentioned to do in the dockerfile
FROM python:latest
COPY src/main.py /usr/local/share/
RUN chmod +x /usr/local/share/src/main.py #<-**--- just add this also
# I have some doubts about the pathing
CMD ["/usr/local/share/src/main.py", "--config=test --results-dir=/home/me/Results"]
Sign up to request clarification or add additional context in comments.
5 Comments
GoingMyWay
Thanks, there are many python files, and sometimes I need to change my python files, so I think cp all my files to images is not practical. Instead, I want to run the task in command line. How can I fix my current issue?
lsd
docker run -it --name test -v
pwd:pwd -w pwd my/code:test python chmod +x "src/main.py && src/main.py --config=test --results-dir=/home/me/Results" Try running two commands sequentially like this.GoingMyWay
Thanks, it is a bit weird, by replace the python commands with pwd, it also returns
/bin/pwd: /bin/pwd: cannot execute binary fileGoingMyWay
Use your suggestion. I got
/bin/bash: python: No such file or directoryGoingMyWay
I followed the code, github.com/oxwhirl/pymarl/blob/master/docker/Dockerfile and github.com/oxwhirl/pymarl/blob/master/run.sh
You can run a python script in docker by adding this to your docker file:
FROM python:latest
COPY src/main.py /usr/local/share/
CMD ["src/main.py", "--config=test --results-dir=/home/me/Results"]
1 Comment
GoingMyWay
Thanks, this is a good method. But how can I fix my current issue? There are many command-line arguments to be passed to python, I prefer to run the code in the command line,
pip installline to set it up; you can put that list of packages into arequirements.txtfile to make it repeatable. What are you gaining by using Docker here?pwd:pwd-wpwdmy/code:test python src/main.py --config=test --results-dir=/home/me/Results", I got/home/docker/miniconda3/bin/python: /home/docker/miniconda3/bin/python: cannot execute binary file