Docker run command could not find the directory on the host

272 Views Asked by At

Trying to run a CLI command using a Pact image as part of Gitlab pipeline. However it is failing as Docker could not find the directory (target/pacts). Below are command and error details.

Command:

docker run pactfoundation/pact-cli:latest  broker publish target/pacts --consumer-app-version=$CI_COMMIT_SHORT_SHA --tag=$CI_COMMIT_REF_NAME --broker-base-url=http://localhost:9090

Error:

Error making request - Errno::ENOENT No such file or directory @ rb_sysopen - /target/pacts
 /usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.29.1/lib/pact_broker/client/pact_file.rb:32:in `read', attempt 1 of 3

As part of pipeline I have run ls target/pacts command just before docker command, and it shows that the directory exists.

I tried to map the the target directory using -v option as below but it still gives the same error.

Altered Command:

docker run -v $(pwd)/target:/target pactfoundation/pact-cli:latest  broker publish /target/pacts --consumer-app-version=$CI_COMMIT_SHORT_SHA --tag=$CI_COMMIT_REF_NAME --broker-base-url=http://localhost:9090

Gitlab pipeline step

contract-publishing:
  image: docker:latest 
  stage: contract-publish
  tags:
    - docker-privileged
  before_script:
    - export      
    - pwd
    - ls -al
    - ls target/pacts
  script:
    - >
      docker run -v $(pwd)/target:/target pactfoundation/pact-cli:latest 
      broker publish /target/pacts
      --consumer-app-version=$CI_COMMIT_SHORT_SHA
      --tag=$CI_COMMIT_REF_NAME
      --broker-base-url=http://localhost:9090

Please help.

1

There are 1 best solutions below

0
On

It seems likely this is a docker related problem - the error is pretty clear. I'd take out the pact image and try something like this:

docker run -v $(pwd)/target:/target debian:latest ls /target/pacts

If that doesn't work, it might be that variable expansion or some other configuration in your gitlab setup is incorrect.