How to run multiple Python scripts and an executable files using Docker?

后端 未结 3 1511
清歌不尽
清歌不尽 2021-01-06 02:19

I want to create a container that is contained with two Python packages as well as a package consist of an executable file.


Here\'s my main package (dockerize

3条回答
  •  萌比男神i
    2021-01-06 02:31

    As mentioned in the documentation, there can be only one CMD in the docker file and if there is more, the last one overrides the others and takes effect. A key point of using docker might be to isolate your programs, so at first glance, you might want to move them to separate containers and talk to each other using a shared volume or a docker network, but if you really need them to run in the same container, including them in a bash script and replacing the last CMD with CMD run.sh will run them alongside each other:

    #!/bin/bash
    
    exec python3 /path/to/script1.py &
    exec python3 /path/to/script2.py
    

    Add COPY run.sh to the Dockerfile and use RUN chmod a+x run.sh to make it executable. CMD should be CMD ["./run.sh"]

提交回复
热议问题