How to Use JuiceFS in Docker

JuiceFS can be integrated with Docker Engine with a volume plugin.

Install plugin

Install the plugin with the following command, some privileges must be granted for FUSE.

$ docker plugin install juicedata/juicefs
Plugin "juicedata/juicefs" is requesting the following privileges:
- network: [host]
- device: [/dev/fuse]
- capabilities: [CAP_SYS_ADMIN]
Do you grant the above permissions? [y/N] y
latest: Pulling from juicedata/juicefs
bb7fe456a3d7: Download complete
Digest: sha256:e49817cdde62aa0596e5d61cbb805ee04c5921322ec696ddfc5e92d0ece4562f
Status: Downloaded newer image for juicedata/juicefs:latest
Installed plugin juicedata/juicefs

Create Volume

Credentials for JuiceFS and object storage access must be provided when creating a new volume:

$ docker volume create -d juicedata/juicefs \
-o name=$JFS_NAME -o token=$JFS_TOKEN \
-o accesskey=$ACCESS_KEY -o secretkey=$SECRET_KEY jfsvolume

You can find JFS_TOKEN in volume setting tab in JuiceFS console, i.e.<jfs_name>/setting

Mount Volume

Mount the volume in Docker. For example

$ docker run -it -v jfsvolume:/jfs busybox ls /jfs

Remove Volume

` $ docker volume remove jfsvolume `

Note that

  1. the volume must be unmounted from all usage before removing.

  2. removing the volume from Docker does NOT affect the data stored in JuiceFS

Disable and remove plugin

$ docker plugin disable juicedata/juicefs
$ docker plugin remove juicedata/juicefs

Using docker-compose

Example for creating and mounting JuiceFS volume with docker-compose

version: '3'
    image: busybox
    command: "ls /jfs"
        - jfsvolume:/jfs
        driver: juicedata/juicefs
            name: ${JFS_NAME}
            token: ${JFS_TOKEN}
            accesskey: ${ACCESS_KEY}
            secretkey: ${SECRET_KEY}

The secrets could be passed via environment variables.

To bring up the services

docker-compose up

To shut down the service and remove docker volumes

docker-compose down --volumes

Use in Docker swarm

JuiceFS volume can be shared in Docker swarm by creating service.

Make sure that volume plugin juicedata/juicefs is installed on every worker node.

Pass options to --mount to create service mounting JuiceFS volume.

docker service create --name nginx --mount \
volume-opt=name=$JFS_VOL,volume-opt=token=$JFS_TOKEN,volume-opt=accesskey=$ACCESS_KEY,volume-opt=secretkey=$SECRET_KEY nginx:alpine