Blog
Jul 23, 2025 - 2 MIN READ
Connecting external drive as Docker volume

Connecting external drive as Docker volume

Quick tip on connecting an external drive as Docker volume.

Melvin Voetberg

Melvin Voetberg

Docker containers isolate workloads from the host, but sometimes you want to keep data on an external disk. In this quick tip, you’ll learn how to:

  1. Identify your external drive
  2. Create a Docker volume that points directly at the block device
  3. Bind‑mount it into a container at runtime
  4. Define it as a named volume in Docker Compose

1. Identify your external drive

Use lsblk or blkid to find the device path and UUID of your drive:

lsblk -f
# or
blkid

Look for your external disk (for example /dev/sdb1). And note its UUID (be874c01-de77-4084-847e-c874bf1b71e8 in this example).


2. Create a Docker volume from the block device

Create a Docker volume that binds directly to the device:

docker volume create hdd \
  --driver local \
  --opt type=ext4 \
  --opt device=/dev/disk/by-uuid/be874c01-de77-4084-847e-c874bf1b71e8 \
  --opt o=bind
  • hdd is the name of your volume.
  • type=ext4 should match your filesystem (e.g. ntfs or xfs).
  • device points at the block device or its UUID symlink.
  • o=bind tells Docker to mount it read/write.

Verify it:

docker volume inspect hdd

3. Bind‑mount at runtime

Use the volume with -v when running a container:

docker run -d \
  --name app \
  -v hdd:/app/data \
  image:latest

This mounts the external drive’s filesystem at /app/data inside the container.

4. Define in Docker Compose

For repeatable setups, add the volume to your docker-compose.yml:

services:
  app:
    image: image:latest
    volumes:
      - hdd:/app/data

volumes:
  hdd:
    external:true

# Or define it directly (skip step 2)
volumes:
  hdd:
    driver: local
    driver_opts:
      type: ext4
      device: /dev/disk/by-uuid/be874c01-de77-4084-847e-c874bf1b71e8
      o: bind

Start it with:

docker-compose up -d

With these steps, Docker will treat your external drive as a normal volume, and data sits right on the disk.