Can anyone tell me where I'm going wrong with this attempt to mount?

I’m having an issue with mounting to docker and wondered if anyone has seen a similar issue. I’ll preface this by saying, if I run the same command with docker running locally, it works fine.I have this defined in a circleCI job:

load_tests_the_second:
executor: general
steps:
  - attach_workspace
  - datadog-agent/setup
  - setup_remote_docker:
        version: default
  - run:
      name: Docker exists
      command: docker -v
  - run:
      command: |
        docker pull grafana/k6:latest
        echo $PWD
        echo "Above is current path"
        docker run -i -v $PWD:/ci/ grafana/k6:latest run /ci/load_tests/tests/backend/basicGET.js 

I end up with the following error:

time="2024-02-28T10:34:25Z" level=error msg="The moduleSpecifier \"/ci/load_tests/tests/backend/basicGET.js\" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://grafana.com/docs/k6/latest/using-k6/modules/#using-local-modules-with-docker."

So despite working locally in docker, it seems to me the local files are not making it to the container. Via circleCI, can I explore the file system on the container? I’ve tried /bin/sh etc without any luck and now I’m stuck.

From a little further debugging, it seems the container is being spun down after the docker run command doesn’t work as anticipated.

Is there anything I can use to get further details about what is going wrong or keep the container alive after docker run so I can figure out a way to inspect this? (have a docker exec command after but given its spun down, obviously it isn’t working)

I see you have some debug commands like echoing the $PWD variable. Check the content of that folder too with the ls command for example. Make sure the file exists.

Also CircleCI supports stopping the build process and allowing you to SSH into the build environment so you can try to run everything manually.

so the $PWD was prior to the docker command, I used that to confirm I’m where I expect to be, so the file should be mounted okay or everything is okay from the local side.

Folder content local side is 100% fine.

How can inspect what I’m doing with the docker run command? I’ve tried sleep on the container or ls etc directly but i’m getting errors:

sudo docker run --user root --name k6_container -d -v $PWD:/ci/ grafana/k6:latest sh sleep 3600

Is there a way I can achieve something like this or direct output as to the file structure on the container from the docker run command?

Thank you for the debug with SSH link, I’m looking into it now

Update

This SSH thing has given me some progress. So I’ve looked at the default image, there’s no ci folder there (expected as this is the image, not my command)

When I create a new image based on the exited container, the logs give me no further detail but I can indeed see a ci folder…one that is empty. So it seems the files/folders aren’t being mounted to the container…anyone have any suggestions why?

My first thought is permissions, but as you can see I’m trying all sorts with sudo/root etc and even before those attempts, this works fine for me on a local docker, just not via circleCI

I’m honestly completely stuck here

sleep commands won’t help, the SSH feature (which you already tried since then) is to way to debug and it can stop the execution after a job.

You are using sudo befoe the docker client command, but even without sudo the daemon is probably running as root and that is what matters. Even when you have permission issues for some reason, there should be an error message, not an empty folder in the container.

Now I start to remember how Docker runs on CircleCI. I implemented my custom builder called “local-builder” because I wanted Docker to work the same way locally as on CircleCI, so I ran my container to run the Docker client inside a container.

On the other hand, I used a variable COPY_MODE to decide whether I wanted to copy the files or mount them. I think the problem is that CircleCI has a remote Docker daemon, and when you are using a remote Docker, you can’t mount a local folder to the remote server. So if you need the files, you probably need to copy them.

CircleCI supports different kind of infrastructures to build (execution environment). You can have a virtual machine, or a container as well. The documentation of the Docker execution environment mentions limitations:

For example not being able to use volumes. I believe they mean bind mounts which is under the volumes section in the compose file. That would make more sense.

Or you can ask for a vitual machine:

With that you would have full controll, and you could install Docker locally, but it would take more time to build docker images as you would have to wait for the virtual machine too.

I tried both ways and I felt using the Docker execution environment and copying files into my build container was a better way, but I recommend you to try and decide what is the best for you.

thank you so much for your time, effort and consideration here. Earlier today I came to the same conclusion as you and finally unearthed some blogs mentioning the circleCI issue with mounting to their docker containers.

Fortunately, I found a workaround to get what I wanted done but this piece of work hurt! Thank you for mentioning your solutions, I’m going to try them out, I did try and machine via circleCI and it didn’t work either oddly but I’ll have another go soon once I give my brain space to decompress