Nikhil Bhat
Nikhil Bhat

Reputation: 23

How to Dockerize multiple python scripts within a .sh script?

I have shell script which contains multiple python scripts (which are run one after another and not in parallel).I need to know how can I dockerize this?

This is My shell script(this takes in one argument of path) -

#!/bin/bash
#parameter from shell
parameter_directory="$1"
# Python script 1
python script1.py --outpath $parameter_directory

# Python script 2
python script2.py $parameter_directory 

# Python script 3
python script3.py $parameter_directory

#Python script 4
python script4.py $parameter_directory

#Python script 5
python script5.py $parameter_directory

#Python script 6
python script6.py $parameter_directory 

Upvotes: 0

Views: 2641

Answers (1)

Oresztesz
Oresztesz

Reputation: 2430

You have to create a folder which has all your files plus your shell script. Let's say the shell script is named as entrypoint.sh. The directory will look like the following:

Dockerfile
entrypoint.sh
script1.py
script2.py
script3.py
script4.py
script5.py
script6.py

Notice, that there's a Dockerfile which will contain the following information:

FROM python:2-slim
WORKDIR /app
ADD . /app
ENTRYPOINT ["./entrypoint.sh"]

Build your docker image using the following command:

docker build -t python-sandbox .

Finally, run your created image in a container using the following command:

docker run -ti --rm --volume parameter_directory:/parameter_directory python-sandbox /parameter_directory

Be aware that Windows and Mac have some limitations when it comes to mounting volumes.

Docker: Sharing a volume on Windows with Docker Toolbox

Upvotes: 2

Related Questions