[SOLVED] Get Cannot unmarshal error when trying use volumes

I need to caches to a docker image.
According to the drone official document,my .drone.yml file contains is:

pipeline:
  setup:
    image: docker
    environment:
      privileged: true
      commands:
         - docker build -t maven:sn .
      volumes:
          - /var/run/docker.sock:/var/run/docker.sock
  build:
    image: maven:sn
    commands: 
      - chmod +x mvnw 
      - ./mvnw package -Pprod,swagger,zipkin docker:build -s /usr/share/maven/conf/settings.xml  -Dmaven.test.skip=true

But, I get some error from UI:
Cannot unmarshal '[/var/run/docker.sock:/var/run/docker.sock]' of type []interface {} into a string value

Who have Any ideas?

not sure if it is related, but I see a few issues with the yaml. The privileged, commands, volumes should not be nested under environment. In fact, environment doesn’t look used at all.

pipeline:
  setup:
    image: docker
-    environment:
-     privileged: true
-     commands:
-        - docker build -t maven:sn .
-     volumes:
-         - /var/run/docker.sock:/var/run/docker.sock
+   privileged: true
+   commands:
+      - docker build -t maven:sn .
+   volumes:
+       - /var/run/docker.sock:/var/run/docker.sock

also it looks like there is an extra space before your volume array item:

    volumes:
-        - /var/run/docker.sock:/var/run/docker.sock
+       - /var/run/docker.sock:/var/run/docker.sock
1 Like

Thank you for your reply. When I solve the yaml file format problem, It can already work normally.

Also since you mount the docker socket most likely you don’t need the privileged flag

I had the same problem, but it was probably related to the new drone file. Here is an example using the new syntax:

---
kind: pipeline
name: default

steps:
    - name: build
      image: docker
      volumes:
        - name: docker_socket
          path: /var/run/docker.sock
      commands:
        - docker build -t my/tag .


volumes:
    - name: docker_socket
      host:
        path: /var/run/docker.sock
1 Like