Search code examples
dockergoogle-cloud-platformgcloudgoogle-cloud-build

How to access a file from Docker image from the host using Google Clould Build


I would like to move node_modules.zip which is inside the Docker image to the static folder found within the directory.

Currently, my cloudbuild.yaml looks as follows:

  - id: package_js
    name: gcr.io/numom-57642/test4:latest
    entrypoint: /bin/bash
    waitFor: ['-']
    args:
      - -c
      - |
        mv node_modules.zip static/

When I run cloud-build-local I get an error:

Step #1 - "package_js": mv: cannot stat 'node_modules.zip': No such file or directory

How can I access node_modules.zip which is part of the Docker Image.


Solution

  • Hmmm.... interesting.

    I think you're on the right path.

    You should be able to copy the file into the default mounted /workspace or a newly mounted volume:

    - id: package_js
      name: gcr.io/numom-57642/test4:latest
      entrypoint: /bin/bash
      volumes:
      - name: 'scratch'
        path: '/scratch'
      args:
      - -c
      - |
        cp node_modules.zip /workspace
        cp node_modules.zip /scratch
    

    And then:

    - id: check
      name: busybox
      volumes:
      - name: 'scratch'
        path: '/scratch'
      args:
      - |
        ls -l /workspace
        ls -l /scratch
    

    Using /workspace is easier as you needn't mount volumes but using /scratch is more explicit.