ModalAI Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    execute script to start docker container on start up

    Ask your questions right here!
    2
    4
    445
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kasarrowtecK
      kasarrowtec
      last edited by

      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 ?

      1 Reply Last reply Reply Quote 0
      • kasarrowtecK
        kasarrowtec
        last edited by

        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
        
        1 Reply Last reply Reply Quote 0
        • Alex KushleyevA
          Alex Kushleyev ModalAI Team
          last edited by Alex Kushleyev

          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.

          1 Reply Last reply Reply Quote 0
          • kasarrowtecK
            kasarrowtec
            last edited by

            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
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB | Contributors