This investigation started when we noticed that this project wouldn't run as expected when installed on an Rpi2. Instead of the electron app, the application only presented a single xterminal, which is the default behavior of xinit.
Let's start by looking into the base image hierarchy. There we find the armv7hf-debian base image. In its Dockerfile we can find this instruction:
ENTRYPOINT ["/usr/bin/entry.sh"]
Now our affected application uses a Dockerfile.template, which is parsed and results in a Dockerfile that looks like this:
FROM resin/raspberrypi2-node:4.0.0
[...]
CMD xinit /usr/src/app/launch_app.sh --kiosk -- -nocursor
The effect of the CMD command is that it passes arguments to the ENTRYPOINT command; for more information you can refer to the related Exec form ENTRYPOINT example in the official Docker documentation.
Also notice that in our app's Dockerfile we use the CMD shell form, so the command will execute in /bin/sh -c
. As a result, the command that will be executed is:
/usr/bin/entry.sh /usr/sh -c xinit /usr/src/app/launch_app.sh --kiosk -- -nocursor
The arguments are then parsed by the entry.sh file:
if [ "$INITSYSTEM" = "on" ]; then
[...]
echo -e "#!/bin/bash\n exec $@" > /etc/resinApp.sh
chmod +x /etc/resinApp.sh
[...]
So the final resinApp.sh on the device looks like this:
#!/bin/bash
exec /usr/sh -c xinit /usr/src/app/launch_app.sh --kiosk -- -nocursor
And there's the issue. /bin/sh -c
expects a string wrapped in '' or "", or else it needs special care to pass the arguments after the next parameter. In our case, xinit will be executed and the rest of the parameters will simply be ignored, as we can see in the related sh(1) section:
The -c option causes the commands to be read from the string operand
instead of from the standard input. Keep in mind that this option only
accepts a single string as its argument, hence multi-word strings must be
quoted.
Now I'm not sure if this is a docker issue or ours, some possible solutions are:
- Support only the CMD exec form (
CMD ["command, "param1", "param2"]
) and update the docs accordingly.
- Update the scripts to handle CMD shell form, i.e wrap the command properly in "".