Pyy
Pyy

Reputation: 367

How to use bash commands alongside Docker restart policies?

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?

Upvotes: 0

Views: 195

Answers (1)

Vinny
Vinny

Reputation: 26

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

Upvotes: 1

Related Questions