docker service create volume code example

Example 1: --constraint node.labels. in compose file

zookeeper:
    image: sweh/test:fake_zookeeper
    deploy:
      replicas: 2
      placement:
        constraints: [node.labels.Zookeeper == true ]
    volumes:
      - "/myapp/zookeeper/data:/usr/zookeeper/data"
      - "/myapp/zookeeper/logs:/usr/zookeeper/logs"
      - "/myapp/zookeeper/conf:/usr/zookeeper/conf"
    environment:
      CFG_FILE: /usr/zookeeper/conf/zoo.cfg

  memcached:
    image: sweh/test:fake_memcached
    deploy:
      replicas: 1
      placement:
        constraints: [node.labels.Memcached == true ]

Example 2: docker create volume

$ docker volume create hello

hello

$ docker run -d -v hello:/world busybox ls /world

Example 3: docker create volume

docker volume create [OPTIONS] [VOLUME]