Trying to understand launcher as a series of Docker commands

AI-generated summary

EricGT is attempting to understand the Docker commands issued by launcher. To achieve this, he has been manually testing the commands and researching the bash script. However, he was struggling to find the input to the host_run() subroutine. Instead of asking multiple questions or adding echo statements, he discovered that using the bash -x option can capture the internal Docker commands and log them to a file. To do this, he used the following steps:

  1. Run the bash command of interest with the -x option, redirecting the output to a file.
  2. Filter the file to show lines with the Docker command using grep.

EricGT provided an example output, which showed the Docker commands being executed by launcher. He concluded that launcher performs a lot of integrity checking, making it a useful tool for regular tasks.

I am trying to understand the Docker commands issued by launcher.

This also requires understanding the other bash commands in the script. As I am no bash expert I have to do some research to figure some parts. Normally I read the code and manually figure out the command and then test run it to make sure, e.g.

docker info 2> /dev/null

Sometimes some of the lines are more complicated and I run an equivalent, e.g.

test=$(($(stat -f --format="%a*%S" /var/lib/docker)/1024**3 < 5)); echo $test

The current subroutine I am working on is host_run() for which I have no idea where the input to the routine is coming from.

https://github.com/discourse/discourse_docker/blob/master/launcher#L259-#L287.

Now I could ask many questions for the next few days or sprinkle echo statements in a modified launcher but there has to be something better.

Is there a means like the command script that will capture the internal Docker commands being run and log them to a file?

EDIT

This seems to work. See: Debugging Bash scripts

Simply use the bash -x option, e.g.

groot@galaxy:/var/discourse$ sudo bash -x launcher start app

To capture this to file

  1. Create directory to hold traces. This is created under the ~ path to avoid permission problems.
groot@galaxy:/var/discourse$ mkdir ~/traces
  1. Run bash command of interest. The trick is that the trace output does not go to stdout, but stderr so use 2> instead of > which is really 1>.
groot@galaxy:/var/discourse$ sudo bash -x launcher start app 2> ~/traces/start_01
  1. Filter the file showing lines with the docker command.
groot@galaxy:/var/discourse$ grep /usr/bin/docker ~/traces/start_01

Example output:

+ docker_path=/usr/bin/docker
+ '[' -z /usr/bin/docker ']'
++ /usr/bin/docker info
+ /usr/bin/docker info
++ /usr/bin/docker --version
++ /usr/bin/docker images
++ /usr/bin/docker run -i --rm -a stdout -a stderr discourse/base:2.0.20200512-1735 echo working
++ /usr/bin/docker info --format '{{.DockerRootDir}}'
+ '[' -z /usr/bin/docker ']'
++ /usr/bin/docker --version
++ /usr/bin/docker ps
++ /usr/bin/docker ps -a
+ /usr/bin/docker start app

That may look like a lot more Docker commands than expected but launcher is doing a lot of integrity checking that you would have to do by hand. This convinces me to use launcher for the regular tasks for which it was created.