0

In a ROS project, I have the following bash script that I use to run a docker container:

#!/bin/bash

source ~/catkin_ws/devel/setup.bash
rosnode kill some_ros_node
roslaunch supporting_ros_package launch_file.launch &

docker run -it \
    --restart=always \
    --privileged \
    --net=host \
    my_image:latest \
    /bin/bash -c\
    "
     roslaunch my_package my_launch_file.launch
    "
export containerId=$(docker ps -l -q)

However, what I'd like to happen is, for every time the container restarts (especially as the machine is booted up), the bash commands preceding the docker run command to also re-run on the host machine (not within the container).

How might I achieve this?

Pyy
  • 327
  • 6
  • 23
  • You'd need some kind of task manager like supervisord or a systemd unit file, on the host, that monitored the container (maybe had a non-background `docker run` as its primary command). The Docker ecosystem largely doesn't run commands directly on the host at all. – David Maze Feb 17 '21 at 15:12

1 Answers1

1

There are a few ways I can think of doing this:

  1. Add this script to a system service. See this answer regarding adding a system service: See this
  2. Add this script into another container that is also set to restart always ... but mount the docker socket into this other container like this: See this
Vinny
  • 26
  • 1