Running a bash script outside of docker container as part of the docker-compose process

re: Technical Support queries

Hi there,

I have configured my application to automatically startup by creating a docker-compose.yml file in


So when the module boots up with torizon it starts to run the docker-compose process. Here is my docker-compose.yml file

version: “2.4”

image: clotspot/lol
# The line below doesn’t work, really need to run this bash shell outside of the container
command: bash -c “source ./”>
privileged: true
# Accept the EULA required to run imx8 vivante graphic drivers
- “55555:55555”
# … for /dev/dri devices
- ‘c 226:* rmw’
- ‘c 199:* rmw’
# … for USB devices
- ‘b 8:* rmw’
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
- type: bind
source: /media
target: /media
propagation: shared
- type: bind
source: /var/run/dbus
target: /var/run/dbus
- data:/opt/data


The problem is that the docker-compose.yml script above does not call the script, and that is needed to connect my bluetooth printer. is a simple script that sets up rfcomm0.


echo "power on " | bluetoothctl | grep power*
echo “devices” | bluetoothctl | grep Device*
echo “trust ${MAC}” | bluetoothctl | grep Pairable*
paired() {
echo “info ${MAC}” | bluetoothctl | grep “Paired” | cut -d " " -f 2

rfcommIn() {
echo “-sh /dev/rfcom0” | rfcomm | grep rfcomm0 | cut -d “:” -f 1

if [ “$(paired)” = “yes” ]; then
echo “Paired”
echo “pair ${MAC}” | bluetoothctl | grep Attempting

if [ “$(rfcommIn)” = “rfcomm0” ]; then
echo “rfcomm device bound on ${MAC}”
echo "no rfcomm, setting up binding printer ${MAC} "
sudo rfcomm bind rfcomm0 14:B4:57:F4:7C:96

  • Inside the debian container there is no bluetooth.service, and setting up the rfcomm0 device first up seems to be the simplest way forward.
  • My app in the container happily prints to the bluetooth device provided is run manually before “docker-compose up” is run manually.
  • The problem is that torizoncore calls up docker-compose, and I can’t see how to execute before starting the container launch process?

Any ideas how I can achieve automatic container boot up which calls the script before launching the container?

Thank you for you help

Fat Linux

Hello @FatLinux ,
This seems to be a recurrent question, there is even an open issue in Docker:

Digging into the comments of this feature request I found this:

I haven’t tried it but it looks promising :slight_smile:
You can try it and let us know the outcome.

Best regards,

As an alternative solution you might be able to do this using systemd services. On TorizonCore there is a service that runs on boot that starts the docker-compose file located at /var/sota/storage/docker-compose/.

This is the service here: meta-toradex-torizon/docker-compose.service at dunfell-5.x.y · toradex/meta-toradex-torizon · GitHub

You could modify or override this service to add the ExecStartPre field as described here: systemd.service

This field will run before the main ExecStart command defined in this service. In this way it may be possible to run your script before your compose file is brought up.

Best Regards,