Skip to content

Configure docker volumes in .gitlab-ci.yml

Description

For CI jobs that build containers and need to interact with and share docker volumes, it would be helpful if the volumes could be specified in .gitlab-ci.yml (and optionally cleaned up by the runner), instead of having to specify the volumes in config.toml.

Proposal

Add a new parameter in .gitlab-ci.yml called volumes which can be used either globally, or in an individual job, that will bind mount the volume. E.g.:

volumes:
  name: named-volume
  path: /path/to/volume/in/container
  mode: rw
  persist: true

The name, path and mode correspond to the three parts of a docker volume mount string (i.e. -v named-volume:/path/to/volume/in/container:rw). The persist keyword is an optional parameter to tell the runner to leave the volume alone at the end of the job, otherwise it will be deleted.

Links to related issues and merge requests / references

None that I know of, although I've seen references to a gitlab-ci.yml version 3 that might support this? Apologies if so.