Question

How to Attach DigitalOcean Block Storage to Docker container?

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?

Thanks!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
October 3, 2019
Accepted Answer

Hello,

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:

  • Prerequisites:

Installation

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

docker plugin install rexray/dobs DOBS_TOKEN=YOUR_DIGITALOCEAN_TOKEN DOBS_REGION=nyc1 LINUX_VOLUME_FILEMODE=0775
  • Change the YOUR_DIGITALOCEAN_TOKEN 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

Output:

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

Output:

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 https://cloud.digitalocean.com 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

Conclusion

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

https://github.com/rexray/rexray

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

https://github.com/rexray/rexray/blob/master/.docs/user-guide/storage-providers/digitalocean.md#do-block-storage

Hope that this helps! Regards, Bobby

The repo is not being maintained as much anymore so be careful.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.