jlesage / docker-firefox

Docker container for Firefox
MIT License
1.61k stars 287 forks source link

Run script or command(s) on startup #181

Closed jladefoged closed 1 year ago

jladefoged commented 1 year ago

I'm trying to add transmission-remote-gtk package using INSTALL_PACKAGES environment variable in docker compose.

transmission-remote-gtk is only available in the Alpine testing repo and I add it manualy at every "boot" using this console command: add-pkg --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing transmission-remote-gtk

And then I start it using this console command: transmission-remote-gtk

Is there an easier way to do this? Maybe run a script or commands on startup?

jlesage commented 1 year ago

You should be able to mount your own init script. It should be mounted under /etc/cont-init.d/ in the container, for example to /etc/cont-init.d/99-myscript.sh. Make sure the script has the execute permission.

jladefoged commented 1 year ago

Script works and runs add-pkg and installs transmission-remote-gtk just fine but fails to launch transmission-remote-gtk with a "cannot open display" error. I think it tries to launch before X display is started? It's better than installing transmission-remote-gtk manually when recreating the docker container :-)

jlesage commented 1 year ago

You could add something like this to your script that would modify /startapp.sh if not already done:

if ! grep -q transmission-remote-gtk /startapp.sh then
    sed -i '/^\/usr\/bin\/firefox .*/i transmission-remote-gtk &' /startapp.sh
fi
jladefoged commented 1 year ago

Works like a charm when I added a ";" in the first line. Thanks.

`if ! grep -q transmission-remote-gtk /startapp.sh; then
    sed -i '/^\/usr\/bin\/firefox .*/i transmission-remote-gtk &' /startapp.sh
fi