简体   繁体   中英

How to run a bash script from dockerfile

I am using a bash script ( run.sh ) to run a python file ( calculate_ssp.py ). The code is working fine. The folder structure is given below

├── dataset
    └── dataset_1.csv
├── Dockerfile
├── __init__.py
├── output
├── run.sh
├── scripts
│   ├── calculate_ssp.py
│   ├── __init__.py

The bash script is

#!/bin/bash

python3 -m scripts.calculate_ssp 0.5

Now, I am trying to run the bash script ( run.sh ) from the Dockerfile . The content of the Dockerfile is

#Download base image ubuntu 20.04
FROM ubuntu:20.04

#Download python
FROM python:3.8.5

ADD run.sh .

RUN pip install pandas
RUN pip install rdkit-pypi

CMD ["bash", "run.sh"]

But, I am getting an error /usr/local/bin/python3: Error while finding module specification for 'scripts.calculate_ssp' (ModuleNotFoundError: No module named 'scripts')

Could you tell me why I am getting the error (as the code is working fine from the bash script)?

You need to package all the files required by your script in the image. You can drop the Ubuntu base image, since it isn't used. (The python base image is based on some other image that already provides bash .)

#Download python
FROM python:3.8.5

RUN pip install pandas
RUN pip install rdkit-pypi

ADD run.sh .
ADD scripts/ ./scripts

CMD ["bash", "run.sh"]

In the Bash script, write a program that creates a file named Dockerfile. The contents of the Dockerfile should have the following commands:

First, the base image should install python3 via the FROM command. Then the rest of the Dockerfile should look like the following:

RUN pip install {{MODULES}} CMD ["python", {{FILENAME}}]

{{MODULES}} should be replaced with the modules: numpy, scipy, and pandas all on one line. {{FILENAME}} should be replaced with./main.pyv

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