Adjusting docker compose file to move the data directory on a different drive

I am using the following docker compose file to install Nextcloud. I want to install Nextcloud on the SSD but have the /data folder on my spinning SSD /dev/sdb but i am not sure on how to properly adjust this.

So far I got this:

services:
  # Note: PostgreSQL is an external service. You can find more information about the configuration here:
  # https://hub.docker.com/_/postgres
  db:
    # Note: Check the recommend version here: https://docs.nextcloud.com/server/latest/admin_manual/installation/system_requirements.html#server
    image: postgres:alpine
    restart: always
    volumes:
      - db:/var/lib/postgresql/data:Z
    env_file:
      - db.env

  # Note: Redis is an external service. You can find more information about the configuration here:
  # https://hub.docker.com/_/redis
  redis:
    image: redis:alpine
    restart: always

  app:
    image: nextcloud:fpm-alpine
    restart: always
    volumes:
      - nextcloud:/var/www/html:z
      # NOTE: The `volumes` config of the `cron` and `app` containers must match
    environment:
      - POSTGRES_HOST=db
      - REDIS_HOST=redis
    env_file:
      - db.env
    depends_on:
      - db
      - redis

  # Note: Nginx is an external service. You can find more information about the configuration here:
  # https://hub.docker.com/_/nginx/
  web:
    image: nginx:alpine-slim
    restart: always
    ports:
      - 127.0.0.1:8080:80
    volumes:
      # https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
      - ./web/nginx.conf:/etc/nginx/nginx.conf:ro  
      # NOTE: The `volumes` included below should match those of the `app` container (unless you know what you're doing)
      - nextcloud:/var/www/html:z,ro
    depends_on:
      - app

  cron:
    image: nextcloud:fpm-alpine
    restart: always
    volumes:
      - nextcloud:/var/www/html:z
      # NOTE: The `volumes` config of the `cron` and `app` containers must match
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis

volumes:
  db:
  nextcloud:

How do I properly set just the /data folder to be on /dev/sdb?

How do I properly set just the /data folder to be on /dev/sdb?

Partition and mount sdb at the host level in the standard Linux fashion (see your distribution docs if necessary).

Then wherever you’ve mounted at the host level goes here:

    volumes:
      - nextcloud:/var/www/html:z
      - /path/on/host:/var/www/html
      # NOTE: The `volumes` config of the `cron` and `app` containers must match

Don’t overlook also adjusting it on your Cron container too.

would this move the entire installation of nextcloud over to the /dev/sdb? or can I just have the hosted data that is synced across devices on the spinning drive and the underlying PHP files and all that on the SSD?

Just the default datadirectory. So just user/app data files.

P.S. You may find the Persistent data section of that image’s documentation of interest.

@jtr I am having some issues here:

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting “/home/throwdating2024/pw_cloud/web/nginx.conf” to rootfs at “/etc/nginx/nginx.conf”: create mountpoint for /etc/nginx/nginx.conf mount: cannot create subdirectories in “/var/lib/docker/overlay2/67f02868677c111ef49977bfa999bf0d5219bff78df08a33abd0854bdfffe0bf/merged/etc/nginx/nginx.conf”: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

this is my docker-compose.yml file:

services:
  # Note: PostgreSQL is an external service. You can find more information about the configuration here:
  # https://hub.docker.com/_/postgres
  db:
    # Note: Check the recommend version here: https://docs.nextcloud.com/server/latest/admin_manual/installation/system_requirements.html#server
    image: postgres:alpine
    container_name: pw_cloud_db
    restart: always
    volumes:
      - db:/var/lib/postgresql/data:Z
    env_file:
      - db.env

  # Note: Redis is an external service. You can find more information about the configuration here:
  # https://hub.docker.com/_/redis
  redis:
    image: redis:alpine
    container_name: pw_cloud_redis
    restart: always

  app:
    image: nextcloud:fpm-alpine
    container_name: pw_cloud_main
    restart: always
    volumes:
      - /media/cloud_drive:/var/www/html
      # NOTE: The `volumes` config of the `cron` and `app` containers must match
    environment:
      - POSTGRES_HOST=db
      - REDIS_HOST=redis
    env_file:
      - db.env
    depends_on:
      - db
      - redis

  # Note: Nginx is an external service. You can find more information about the configuration here:
  # https://hub.docker.com/_/nginx/
  web:
    image: nginx:alpine-slim
    container_name: pw_cloud_nginx
    restart: always
    ports:
      - 127.0.0.1:8080:80
    volumes:
      # https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
      - ./web/nginx.conf:/etc/nginx/nginx.conf:ro  
      # NOTE: The `volumes` included below should match those of the `app` container (unless you know what you're doing)
      - /media/cloud_drive:/var/www/html
    depends_on:
      - app

  cron:
    image: nextcloud:fpm-alpine
    container_name: pw_cloud_cron
    restart: always
    volumes:
      - nextcloud:/var/www/html:z
      # NOTE: The `volumes` config of the `cron` and `app` containers must match
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis

volumes:
  db:
  nextcloud:

not sure what i am doing wrong here.