How to Start Docker After Restarting Yocto Linux

If you are using Yocto Linux and notice that Docker isn’t running after a restart, don’t worry. Due to Yocto’s lightweight setup, managing services like Docker requires a slightly different approach compared to traditional Linux distributions. In this article, we’ll walk you through the steps to get Docker up and running on Yocto Linux, including setting up Docker as a service.

Step 1: Check if Docker is Installed

Before diving into starting Docker, ensure that it is installed on your system. Run the following command:

docker --version

If Docker isn’t installed, you’ll need to include it in your Yocto image during the build process or install it using your system’s package manager (if available).

Step 2: Manually Start Docker

Unlike traditional distributions, Yocto may not include service management tools like systemctl. To start Docker manually, use:

dockerd &

This command starts the Docker daemon in the background. Depending on your system configuration, you may need to specify options such as the data directory or network settings. Remeber to add the “&” at the end to run in background.

Step 3: Automate Docker Startup

To ensure Docker starts automatically after a system reboot, you’ll need to set up an init script. Here’s an example script you can use:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          docker
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Docker Daemon
### END INIT INFO

case "$1" in
    start)
        echo "Starting Docker..."
        dockerd &
        ;;
    stop)
        echo "Stopping Docker..."
        killall dockerd
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac
exit 0

Steps to Use the Script:

  1. Save this script as
    /etc/init.d/docker.
  2. Make the script executable:
    chmod +x /etc/init.d/docker
  3. Add it to the default run levels:
    update-rc.d docker defaults

Now, Docker will start automatically when you boot up your Yocto Linux system.

Step 4: Specify Restart in Docker Compose

After restarting Yocto OS, Docker will start with the above setup. However, if you need your Docker applications to start automatically, you must set the restart option in your Docker Compose file. Here’s an example:

version: '3.8'
services:
  my-service:
    image: my-docker-image
    restart: always
    ports:
      - "8080:8080"

This setup ensures that your application will restart automatically if it stops or when the system reboots. Docker Compose also provides additional restart policies, such as no, on-failure, and unless-stopped. Select the one that suits your needs best. Setting up these options is a key step in configuring Docker as a service for your applications

Conclusion

Managing Docker on Yocto Linux might seem tricky at first, but with the right approach, it’s straightforward. By following these steps, you can start Docker manually and even automate its startup process for future reboots. Yocto Linux is also commonly used in Programmable Logic Controller (PLC) systems, providing a flexible and customized operating system for industrial automation and control applications. Whether you’re using Yocto for embedded development or lightweight systems, ensuring Docker is up and running as a service is crucial for containerized workflows.

Have questions or need further assistance? Message me I can help you!

Share your love