Skip to main content

Sharing Docker Volumes in DDEV

· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

In a recent project, we dealt with 2 DDEV instances — 2 applications that need to communicate with each other or, more specifically, exchange files.

Since DDEV is mainly a wrapper around Docker and Docker Compose, we can use shared Docker volumes to achieve our needs.

First, let's create the shared Docker volume with the following command:

docker volume create customer-shared-volume

Next, in both DDEV projects, we need to add another Docker Compose file to configure the shared volume for the web container, which is where our apps are running in.

Create a new file .ddev/docker-compose.mounts.yaml with the following content:

services:
web:
volumes:
- "shared-vol:/var/www/html/shared-volume:rw"

volumes:
shared-vol:
name: "customer-shared-volume"
external: true

2 important things to mention:

  1. The shared volume shared-vol needs to have a name configured. Otherwise, Docker and Docker Compose, specifically, will prefix the shared volume with the project name, and thus, you will end up with two distinct volumes that do not share the files.
  2. The external: true flag is important because last year, Docker Compose version 2.19.1 implemented some tighter security checks. I blogged about a similar problem I had with shared networks last year.

Once you have added the .ddev/docker-compose.mounts.yaml in each project, you can ddev start your projects, and the shared volume should be available in both applications.