Docker Community Forums

Share and learn in the Docker community.

Shared volumes with docker-compose run from container

Hi, I’m having a strange behavior when running docker-compose from a gitlab runner.
Here’s my configuration:

I’m using docker gitlab-runners to start docker-compose with the following .gitlab-ci.yml:

stages:
  - run

# Official docker compose image.
image:
  name: docker/compose:1.23.2 # update tag to whatever version you want to use.
  entrypoint: ["/bin/sh", "-c"]

services: # is that really necessary? behavior seems the same with or without
  - docker:dind

before_script:
  - docker version
  - docker-compose version

run_compose:
  stage: run
  script:
    - mkdir /c
    - touch /c/__CREATED_FROM_RUNNER__
    - docker-compose down -v
    - docker-compose build
    - docker-compose up
    - ls -l /c
  artifacts:
    paths:
      - /c/*

The docker-compose.yml used in the previous script version looks like this:

version: "3"
services:
  snitch:
    image: snitch:latest
    environment:
      - PROGRAM_NAME=${PROGRAM_NAME}
    volumes:
      - /c:/caps

  xtools:
    image: xtools:latest
    environment:
      - PROGRAM_NAME=${PROGRAM_NAME}

The “snitch” container is writing files to the /caps directory. I assumed that the volume section meant that the /c directory in the runner container would receive the files, and that they would be collected as artifacts.

The actual behavior is that the /c directory of the container is empty (only the file created by the touch command in the .gitlab-ci.yml is present), but there’s a /c directory created on the physical machine of the runner with the files inside it (!), but without the __CREATED_FROM_RUNNER__ file.

Any insights about what’s happening would be greatly appreciated. Plus, how can I retrieve the created files as artifacts?

Thanks