mazma Posted July 5, 2015 Share Posted July 5, 2015 I'd like to run a .sh script in the background when a docker image starts. Some suggestions I've seen are using crontab @reboot or calling the script from rc.local. I've tried both without success but I'm not sure if I'm doing it right anyway. Any suggestions would be appreciated. Thanks. unRaid 6.0 Quote Link to comment
mazma Posted July 5, 2015 Author Share Posted July 5, 2015 Its the script Newznab uses to update the index. I've been using Docker exec to get into the container. Quote Link to comment
ironicbadger Posted July 5, 2015 Share Posted July 5, 2015 I'd rebuild the image using the Dockerfile to run your script at build time or modify the CMD to include your script somehow. Does that suit your needs? Quote Link to comment
mazma Posted July 5, 2015 Author Share Posted July 5, 2015 I'd rebuild the image using the Dockerfile to run your script at build time or modify the CMD to include your script somehow. Does that suit your needs? I didn't build the image and have no idea how to So kinda stumped at this point. Prior to this I'd exec into the docker and start the script and leave it, but now the tower is headless so can't do it. Quote Link to comment
Squid Posted July 5, 2015 Share Posted July 5, 2015 I'd rebuild the image using the Dockerfile to run your script at build time or modify the CMD to include your script somehow. Does that suit your needs? I didn't build the image and have no idea how to So kinda stumped at this point. Prior to this I'd exec into the docker and start the script and leave it, but now the tower is headless so can't do it. You could probably make a script and place it in the appropriate folder according to this: http://lime-technology.com/forum/index.php?topic=26201.0 to execute when the array is started (with an appropriate delay to let the container get up and running) that would issue the docker exec commands required. (or do it manually through telnet - no reason why you can't do it simply because the system is headless) Quote Link to comment
ironicbadger Posted July 5, 2015 Share Posted July 5, 2015 I'd rebuild the image using the Dockerfile to run your script at build time or modify the CMD to include your script somehow. Does that suit your needs? I didn't build the image and have no idea how to So kinda stumped at this point. Prior to this I'd exec into the docker and start the script and leave it, but now the tower is headless so can't do it. Give us some more info then. What's the script you need to run? Which container etc.... Quote Link to comment
sparklyballs Posted July 5, 2015 Share Posted July 5, 2015 Its the script Newznab uses to update the index. I've been using Docker exec to get into the container. which container ? Quote Link to comment
mazma Posted July 5, 2015 Author Share Posted July 5, 2015 Its the script Newznab uses to update the index. I've been using Docker exec to get into the container. which container ? Apache-php by tutum Quote Link to comment
sparklyballs Posted July 5, 2015 Share Posted July 5, 2015 doesn't the newznab container handle updates ? and if not, why the hell not ? Quote Link to comment
mazma Posted July 5, 2015 Author Share Posted July 5, 2015 doesn't the newznab container handle updates ? and if not, why the hell not ? theres a newznab container now? I tweaked this image some time ago so never looked for anything else. Quote Link to comment
mazma Posted July 5, 2015 Author Share Posted July 5, 2015 doesn't the newznab container handle updates ? and if not, why the hell not ? If it's setup properly it should. A newznab container should have startup/cron/at jobs scheduled inside of it. Which repo is it in? Quote Link to comment
dtempleton Posted September 13, 2015 Share Posted September 13, 2015 I'd like to run a .sh script in the background when a docker image starts. Some suggestions I've seen are using crontab @reboot or calling the script from rc.local. I've tried both without success but I'm not sure if I'm doing it right anyway. Any suggestions would be appreciated. Thanks. unRaid 6.0 This topic seems to have been dropped, but I had the same question and figured out one way. The Docker "run" syntax includes a target script/argument $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] See https://docs.docker.com/reference/run/ I wanted to run a target script /my/script/lives/here/script.sh but I couldn't find where to put that in the UNRAID docker template. I first tried to edit the container from the UNRAID Docker page and paste the path in the docker "extra parameters" field within UNRAID. This works for --cpuset-cpus but adding the script path just deleted the container, though it was easy to restore. Instead, I decided to do it through the CLI. First, I restarted the container, and copied the command that was successfully loaded. Then in terminal I ran docker stop <container> docker rm <container> To stop and then remove the image and then pasted the run command from the UNRAID page and added <space>/my/script/lives/here/script.sh This is literally the command (deleting port numbers): /usr/bin/docker run -d --name="handbrake" --net="bridge" -e WIDTH="1280" -e HEIGHT="720" -e TZ="America/New_York" -p 8**2:8080/tcp -v "/mnt/user/Media/":"/media":rw -v "/mnt/user/Media/handbrake_watch/":"/input":rw -v "/mnt/cache/appdata/handbrake/":"/nobody/.config/ghb":rw -v "/mnt/user/Media/handbrake_out/":"/output":rw --cpuset-cpus="3" pinion/docker-handbrake-cli:latest nobody/.config/ghb/scripts/convert.sh Executing it gave a running container that launched my script. I wasn't sure if the cmd-script would be launched upon container restart, but it is. Now when I start or restart the container the script is launched inside it. The script directory is mapped in the container, so I can edit it in /mnt/cache/appdata/etc The suggestion to edit the container works and I tried that in an earlier iteration, which worked after 'committing' the container. However you will lose these edits if you update the image, which is surprisingly easy to do; it happened to me twice. I like having an editable script launched with the container that can easily be rebuilt. Hope yours works. Dennis 1 Quote Link to comment
rgreenpc Posted August 17, 2020 Share Posted August 17, 2020 Kind of reviving an old topic but not sure if anything has changed in the past few years... I need to run sudo sed -i 's/curl -s/curl --compressed -s/' /opt/pihole/gravity.sh every time my Pihole container starts Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.