Gitlab docker run cannot mount ${CI_PROJECT_DIR} folder

Viewed 606

The build container has access to the docker socket through a bind mount. In a pipeline, the following will not work (resulting in an empty /project directory):

    - docker run
      --volume ${CI_PROJECT_DIR}:/project
      image-name

Instead, I had to find the container name of the build container and attach its volumes to my new container:

    - |
      docker_ps_output=$(docker ps --format "{{.Names}}" --filter "label=com.gitlab.gitlab-runner.job.id=${CI_JOB_ID}")
      readarray -t gitlab_container_names <<<"$docker_ps_output"

      for container_name in "${gitlab_container_names[@]}"
      do
        if [[ $container_name == *"build"* ]]; then
          echo "Found build container $container_name"
          export BUILD_CONTAINER_NAME=$container_name
          break
        else
          echo "Ignoring ${container_name}. We are looking for the build container".
        fi
      done

      if [ -z $BUILD_CONTAINER_NAME ]; then
        echo "Could not find build container name"
        exit 1
      fi
    - docker run
      --volume-from=$BUILD_CONTAINER_NAME
      image-name

Is this a problem on my end, a limitation of Docker (a container not being able to mount one of its volumes onto a new container) or an issue with Gitlab?

0 Answers
Related