How to Attach DigitalOcean Block Storage to Docker container?

Posted October 3, 2019 8.9k views
Linux BasicsDockerBlock Storage

Hi all,

Does anyone know if it is possible to mount a DigitalOcean block storage to a docker container and if so what is the best way to do so?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


The last time I had to do that I used the REX-Ray storage plugin. It officially comes with DigitalOcean Block Storage support.

I’ll try to walk you through the whole process here:


To install the REX-Ray Docker plugin run the following:

  • Change the YOURDIGITALOCEANTOKEN with your actual DigitalOcean Token

  • You can change the nyc1 part with the region that you would like your Block Storage to be deployed at

  • You can change the LINUX_VOLUME_FILEMODE according to your needs

To check if the plugin was installed successfully run:

docker plugin ls


ID                  NAME                 DESCRIPTION                               ENABLED
fcb931b51f5a        rexray/dobs:latest   REX-Ray for Digital Ocean Block Storage   true

Creating a volume

Once you have the REX-Ray plugin installed, you can go ahead and create a volume:

docker volume create --name=my-dobs --opt=size=10 --driver=rexray/dobs
  • You can change the my-dobs with the name that you would like to use for your volume

  • The --opt=size=10 indicates the size of the DigitalOcean block storage that you would like to be created

To check if the volume was created successfully run:

docker volume ls


DRIVER               VOLUME NAME
rexray/dobs:latest   my-dobs

This would also create a new volume under your DigitalOcean account. To see it you just go to your DO control panel at then from the menu on the right click on Manage and then click on Volumes. There you would be able to see the volume with the name that you’ve specified as a --name argument and the size you’ve selected.

Mounting the new volume to a container

Then to mount the new volume just run the following:

docker run -ti -v my-dobs:/my-folder busybox

This would attach you to the container straight away. You can also check if this worked by running the following:

df -h | grep my-folder

The out put should look something like this:

/dev/sda                  9.8G     36.0M      9.2G   0% /my-folder


For more information about the plugin you can visit their official GitHub repo here:

And for more information about the Docker integration, you could visit this page here:

Hope that this helps!

by Brian Hogan
Docker is an application that simplifies the process of managing application processes in containers. In this tutorial, you'll install and use Docker Community Edition (CE) on Ubuntu 18.04. You'll install Docker itself, work with containers and images, and push an image to a Docker Repository.
  • Clear answer! Thank you so much!

  • Hello, I tried to deploy in swarm mode with replicas to share volume in all nodes and found that it didn’t work. Does this solution work on swarm mode with replicas?

    • Hi there,

      I have not tested this with Docker Swarm and multiple replicas, but I recently had to set it up for Kubernetes and multiple pod replicas and it worked well:

      What is the error that you get when you try to attach the volume to multiple containers?


      • Hi Bobby,

        It seems that I have to attach the new volume to droplet before mount volume to container on that droplet.

        Before that, I have a droplet without any volume attached to it. Then I install the rexray/dobs plugin and create the volume using rexray driver. It worked smoothly. The problem occured when I start deploying new stack with service has volume mounted to. API of Digital Ocean return 500 error.

        docker: Error response from daemon: error while mounting volume '/var/lib/docker/plugins/f398214a855ead0a3d6dda143e915d2004df19fd9eb80bb90b40af31ecf890ba/rootfs': VolumeDriver.Mount: docker-legacy: Mount: do: failed: POST 500 Server Error.
        ERRO[0007] error waiting for container: context canceled