Tuesday, March 15, 2022

[SOLVED] Mounted host volume is not writable from host in Azure Pipelines

Issue

I'm mounting a volume from host to container which will not be present at the time of running the docker container.

  volumes:
    - "../foo:/app/foo"

The foo folder will be created by the docker. The container will create additional folders and files inside foo. Similarly one more app inside the host will create additional folders and files inside foo. My expectation is that all the content should be placed inside the foo folder from the container app and the host app.

This works fine in the Mac, but running the same in Azure Pipelines fails to create additional files and folders from the host.

Error: EACCES: permission denied, mkdir './foo'
      at Object.mkdirSync (fs.js:921:3)

I have tried adding z at the end of volume mount but it didn't worked - ../foo:/app/foo:Z. I tried to run chmod, but the operation is not permitted.

Azure Pipeline:

pool:
  vmImage: 'ubuntu-latest'

Solution

You could try this to make a folder on a pipleine:

- task: CmdLine@2
  inputs:
    script: 'mkdir .foo' 
    workingDirectory: System.DefaultWorkingDirectory
   

so that would essentially make a .foo folder in System.DefaultWorkingDirectory/.foo

Now if you then wanted to go into that folder you can do:

- task: CmdLine@2
  inputs:
    script: |
      cd '($System.DefaultWorkingDirectory)/.foo'
      dir

Or you could do to just see the full path to ref in your code:

- task: CmdLine@2
      inputs:
        script: |
          echo '($System.DefaultWorkingDirectory)/.foo'

Then once the file has been made you can mount it using docker an answer here may help with that:

Mounting a host directory to a docker container from yaml/compose file

Essentially you have to switch your steps around.



Answered By - Jason
Answer Checked By - Marie Seifert (WPSolving Admin)