I use the python image to run multiple python 2 scripts every few minutes. But this way I have to start a container multiple times. Is there a best practice to avoid this?
Notice the “detached” flag -d above. Your container will be running in the background as you can see by inspecting via docker ps. This trick is possible for this image but in other cases, it depends on the image you use. More specifically, it depends on the entrypoint and also if it has bash installed in the image. (This is a side note and adding for clarification, FYI) Then you could execute the commands on the container directly using exec:
I notice you are running your container in interactive mode. Another possible approach would be accessing the container by creating a bash session and then executing the commands within the container via the interactive session. It would be something like this: