docker (w/socket bind) CI run fails with containers left running

Summary

Using docker socket binding if you interrupt a CI bash script, the docker instances it spawned on the host remain running.

I'm using docker run with --rm so that no lingering docker containers remain afterwards.

Successful/complete script runs result in proper behaviour.

Steps to reproduce

  1. Start docker containers that take awhile to start up, from within the docker socket binding container instance.
  2. Cancel the job after the docker run, and before it's stopped.

Example Project

I don't have a lot of time, but I will endeavour to create a project if necessary. I'm still new to gitlab CI, so it might take me awhile to create a separate project for this.

What is the current bug behavior?

The docker containers started remain running on the docker host.

What is the expected correct behavior?

I should either be able to "catch" the signal interrupts, thereby stopping the docker instances, or the gitlab system should.

I use the following bash code to hook interrupts. Is there a different kill signal being sent to the process?

trap process_interrupt HUP
trap process_interrupt QUIT
trap process_interrupt KILL
trap process_interrupt TERM
trap process_interrupt INT
trap process_interrupt USR1

function process_interrupt() {
        echo "** Trapped CTRL-C or TERM, cleaning up".
        docker stop mongo
        docker stop node-notes
        exit 1;
}

Relevant logs and/or screenshots

I would have expected "** Trapped CTRL-C or TERM, cleaning up" to be printed to the console, but instead, the script just terminated with no extra output, so there's no use in pasting it here.

Output of checks

This bug happens on GitLab.com, while running a docker socket binding container instance on my machine.

It was started with the following command...

docker run -d --name docker --hostname docker --restart always -v \
/srv/docker-runner/config:/etc/gitlab-runner --ip 172.27.0.11 -v \
/var/run/docker.sock:/var/run/docker.sock --net intelli-notes container-id-here

Results of GitLab environment info

unsure of how to get this, no omnibus package is installed on my gitlab runnes.

Results of GitLab application Check

ditto here.

Possible fixes

  1. Send a catchable signal
  2. Intercept docker containers started by the CI run, and stop them all.
Assignee Loading
Time tracking Loading