Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Run script when docker starts

Featured Replies

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

  • Author

Its the script Newznab uses to update the index. I've been using Docker exec to get into the container.

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?

  • Author

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.

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)

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....

Its the script Newznab uses to update the index. I've been using Docker exec to get into the container.

 

which container ?

  • Author

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

  • Author

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.

  • Author

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?

  • 2 months later...

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

 

  • 4 years later...

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

 

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.