Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Init script #249

Open
tigerkzr opened this issue Jun 13, 2023 · 2 comments
Open

Custom Init script #249

tigerkzr opened this issue Jun 13, 2023 · 2 comments

Comments

@tigerkzr
Copy link

tigerkzr commented Jun 13, 2023

Is there a way of running a custom init script at container start?

the gist:
At container startup, set a default route within the torrent container so that traffic goes through through my VPN container that uses IP masquerade. (I am avoiding setting the network mode to container or service)

how I normally accomplish this:
Using linuxserver images, one can just mount a script into the container at ./script/dir:/custom-init-script.d and the container will run every script there at startup

What I have tried:
mount script into cont-init: ./script.sh:/etc/cont-init.d/99-script.sh
result: Container starts but script fails
Command line is not complete. Try option "help"
/var/run/s6/etc/cont-init.d/99-script.sh: line 7: curl: command not found

mount script directory into container and use command in docker compose 'command: /script/dir/script.sh
result:
Script works but the container goes on a restart/terminate loop.

I can run the script after container startup using docker exec, and it works, but this doesn't persist between restarts.

script I am trying to run(env vars are passed via docker compose environment:):

#!/bin/bash

ip route del default
ip route add default via ${VPN_CONT_IP}
ip route add ${HOST_LAN:-10.0.1.0/24} via 10.0.10.1

wanip=$(curl icanhazip.com)

echo "##############################################################"
echo "# Now routing through ${VPN_CONT_IP} to WAN IP $wanip. #"
echo "##############################################################"

any suggestions on how I can accomplish this are greatly appreciated

@gnammix
Copy link

gnammix commented Jul 29, 2023

Similar issue here, would like to set WAN and incoming port at container startup. I could probably achieve that by running a script at startup.

@trunet
Copy link

trunet commented Oct 16, 2023

I agree that this should be done properly, but mounting a shell script into /etc/cont-init.d worked fine for me. Try to add the full path to the curl command like /usr/local/bin/curl, it's possible that the s6-init is not appending all the known bin locations on PATH environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants