execute script to start docker container on start up



  • Hi,

    i am trying to execute a script that will start a docker container every time the VOXL is started.

    A lot of the suggestions for running a script on start up on linux like using crontab or systemd or rc.local is not available with this custom yocto build on the VOXL.

    Does anyone have the best way of doing this ?



  • The most promising way seemed to be to make a service file in etc/systemd/system -

    [Unit]
    Description=Starts the mastervoxl docker container on startup.
    
    [Service]
    Type=simple
    ExecStart=/bin/bash /home/root/mastervoxl_init.sh
    
    [Install]
    WantedBy=multi-user.target
    

    and the script mastervoxl_init.sh being -

    #!/bin/bash
    echo 'initializing mastervoxl docker container'
    docker run -it mastervoxl /bin/bash
    

  • Dev Team

    systemd is available on VOXL, so you could go ahead and try using the service file and script you wrote. Did you try it? However, you need to make sure that the Docker service is running, so your service file should require the Docker service also running. Docker is started by systemd as well.



  • So i managed to get it to work with the following service file and script file -

    [Unit]
    After=docker-autorun.service
    
    [Service]
    Type=simple
    ExecStart=/bin/bash /home/root/mastervoxl_init.sh
    
    [Install]
    WantedBy=multi-user.target
    
    #!/bin/bash
    echo 'initializing mastervoxl docker container'
    docker run --restart=always -i mastervoxl /bin/bash
    

Log in to reply