简体   繁体   中英

Running docker from inside python script doesn't work on startup

So I have a simple python script that is set to run on startup. This script ideally runs a webhook that then runs a docker container upon a received POST request. This script works perfectly fine when I run it, but when I put it in my crontab, it all of a sudden doesn't seem to work and I can't completely figure out why. I have the script set to wall a message upon receiving a successful post method, so I know that isn't the problem as I see the wall message just fine whenever I send a POST. It just doesn't seem to actually start the container, no matter whether I tell it to run in the background, normally, with subprocess.Popen or with subprocess.call, with shell true or false.

        subprocess.call(["echo PULLING APP | wall"], shell=True)
        subprocess.call([". [pathtoscript], shell=True)

This is the excerpt of the.py. It may be somewhat useful to note that I don't test the script until the computer is fully booted up, to ensure that I am not somehow running this before the docker service starts or something like that. The script:

#!/bin/sh
docker run --name [app] -p 80:80 --rm --mount type=bind,source=/home/dev/mongodb.pass,target=/app/mongodb.pass [pathtoimage]

Ok, so I seem to have solved the problem by ensuring I use the absolute path to docker inside of the shell script using which docker

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