1

I'm new to docker so I'm sure what I am missing is as simple as a few words but I can't figure it out despite googling for a couple of hours.

python_code_to_run.py: Just loads a dataset and saves it...

import pandas as pd 
import numpy as np 
import os 
import h2o
from h2o.estimators.gbm import H2OGradientBoostingEstimator

airlines= h2o.import_file("https://s3.amazonaws.com/h2o-public-test-   
data/smalldata/airlines/allyears2k_headers.zip")

airlines_data = pd.DataFrame(airlines)
airlines_data.to_csv('airlines_dataset_dled.csv', index=False )

DockerFile: This runs when I use the -build command just fine...

From python:3.7-slim-buster

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get -y install unzip build-essential libaio-dev


RUN python3 --version
RUN pip3 --version
RUN mkdir -p /src

COPY . /src
COPY /app/python_code_to_run.py /src

RUN chmod +x src/run_py_file.sh
RUN chmod +x src/python_code_to_run.py


COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

CMD [ "/bin/sh", "docker_test.sh" ]
#ENTRYPOINT [ "bash" ,  "run_py_file.sh" ] # doesn't work either

** run_py_file.sh**

python /app/python_code_to_run.py

I have a folder:

 - LearningDocker

    DockerFile

    script_to_trigger_code.sh
    - app

     - python_code_to_run.py

I can build the docker image just fine by running:

 docker build -t my_attempt_to_learn_docker .

I will then take the ID# that it gives me and run:

docker run -v /Users/myname/Documents/docker_folder f28384723

I keep getting the error

**/bash: run_py_file.sh: No such file or directory**

Can someone please help me out with what I am missing here? I'm struggling to learn how to do this properly because I can't get my first bit of code up and running. The app/python_code_to_run.py is DEFINITELY located and spelled exactly like that. Same with the sh file.

I've tried a million combinations of things for CMD ["run_py_file.sh"] but I just can't figure this part out. I must be missing magic combination of what to put in the CMD / ENTRYPOINT part of code in order to get this to run. Any help is appreciated!!

runningbirds
  • 6,235
  • 13
  • 55
  • 94

2 Answers2

1

Add WORKDIR to your dockerfile pointing at /src. Your CMD instructions is executed in the default WORKDIR for the python image, probably at the root dir, not in reach of your .sh file.

0

It doesn't look like you actual have a file called run_py_file.sh in your host directory structure, but you're referencing a different script in the Dockerfile.

I think the core issue is that the working directory defaults to /, but your CMD and ENTRYPOINT blocks assume you're in the /src directory.

Try adding a WORKDIR /src block to your dockerfile, or using an absolute path to the actual file being copied in your CMD or ENTRYPOINT blocks.

CMD [ "/bin/sh", "/src/script_to_trigger_code.sh" ]

Cameron Little
  • 3,487
  • 23
  • 35
  • Thank you for your feedback. I made this change and now I get python: can't open file '/app/python_code_to_run.py': [Errno 2] No such file or directory. I placed the WORKDIR /src directly above the CMD line. Any guidance? – runningbirds Apr 11 '20 at 07:24
  • The `app` dir doesn't exist in your Docker container, since you've moved things into the `src` directory. I wouldn't use the shell script at all, and would just us `CMD ["python", "/src/python_code_to_run.py"]` – Cameron Little Apr 11 '20 at 07:34