jlesage / docker-firefox

Docker container for Firefox
MIT License
1.42k stars 267 forks source link

Unable to run container with custom `CMD` #139

Closed aofei closed 1 year ago

aofei commented 1 year ago

Before, I used to do something special by moving /init to ENTRYPOINT and overriding CMD. Like automatically stopping the container after running for a while:

$ docker run -d --name firefox -p 5900:5900 --shm-size 2g --entrypoint /init jlesage/firefox /bin/sh -c "sleep 300"

This is all thanks to the previous /init file:

#!/bin/execlineb -S0

##
## load default PATH (the same that Docker includes if not provided) if it doesn't exist,
## then go ahead with stage1.
## this was motivated due to this issue:
## - https://github.com/just-containers/s6-overlay/issues/108
##

/bin/importas -D /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PATH PATH
export PATH ${PATH}
/etc/s6/init/init-stage1 $@

But with the latest version it is no longer possible to do so. Because /init file was completely changed, support for $@ has been removed. I don't know if this is intentional, so I wonder if it's possible to add it back? I have a lot of batch jobs relying on this feature, so it's kinda important to me.

jlesage commented 1 year ago

Yeah as you saw, things changed a lot because S6 is no longer used.

If you describe your needs we can see if there is alternate ways to do the same thing. For example, I see multiple ways to automatically stop the container after a certain amount time.

The other alternative is to stick to the previous version by using the proper Docker image tag.

aofei commented 1 year ago

If you describe your needs we can see if there is alternate ways to do the same thing.

All I want is to be able to have it automatically execute a script after Firefox has successfully started without writing a Dockerfile. Mounting the script to /etc/cont-init.d might be an option, but I don't know how to monitor whether Firefox has successfully started.

For example, I see multiple ways to automatically stop the container after a certain amount time.

May I ask what is your best advice for automatically stopping containers?

jlesage commented 1 year ago

You can probably mount a new "service" under /etc/services.d. This service can be "one shot", meaning that it is executed once. See https://github.com/jlesage/docker-baseimage#services for more details on how to define a service.

Basically, you should mount a new directory (e.g. /etc/services.d/my_script) that contains the following files:

You should also add/mount the file /etc/services.d/default/my_script.dep to make your service part of defaults ones.

jlesage commented 1 year ago

To automatically stop the container, could you do it "externally" ? Example:

docker run -d --name firefox -p 5900:5900 --shm-size 2g
sleep 300
docker stop firefox
aofei commented 1 year ago

To automatically stop the container, could you do it "externally" ? Example:

My batch jobs are fired by nomad, so getting the docker stop to work is a bit hacky.

You can probably mount a new "service" under /etc/services.d.

So I ended up choosing this way. And it works. Thanks for your help! ❤️

jlesage commented 1 year ago

Great!