Permissions denied errors after migration

Your question

I ran

docker compose run --rm migrate run   \
  --final \   
  --source /etc/stalwart/config.json \  
  --target /etc/stalwart-v1/config.json \  
  --state /var/lib/stalwart-migrate  \
  --target-path-map /var/lib/stalwart=/var/lib/stalwart-v1  \
  --owner 2000:2000

and there were no errors, but when I started v1, I got

stalwart-v1  | ⚠️ Startup failed: Failed to create database directory /var/lib/stalwart-v1/: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }

Both Stalwarts (the old and new) run in docker

with Stalwart V1 having the compose file:

networks:
  ip6net:
    enable_ipv6: true
    ipam:
      config:
        - subnet: fd00::/8
services:
  stalwart-v1:
      image: stalwartlabs/stalwart:v1
      container_name: stalwart-v1
      init: true
      restart: unless-stopped
      env_file: "stalwart.env"
      ports:
        - "25:25"
        - "465:465"
        - "993:993"
       # - "995:995"
        - "4190:4190"
       # - "443:443"
        - "127.0.0.1:8081:8080"
      volumes:
        - stalwart-v1-etc:/etc/stalwart
        - stalwart-v1-data:/var/lib/stalwart

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

The 1.0 container is probably failing because the data volume is mounted at a different path from the one the migrated configuration names.

The error says the server tried to create /var/lib/stalwart-v1/. That means the target config.json names /var/lib/stalwart-v1 as the data path. Your v1 compose file mounts the data volume at /var/lib/stalwart, so /var/lib/stalwart-v1 doesn’t exist inside the container. The server runs as uid 2000, which can’t create a directory under /var/lib, hence the permission denied. Your --owner 2000:2000 is correct and is probably not the problem.

The docs describe two ways to line the paths up. The first is to mount the data volume at the path the target configuration names:

    volumes:
      - stalwart-v1-etc:/etc/stalwart
      - stalwart-v1-data:/var/lib/stalwart-v1

The second is to keep the mount at /var/lib/stalwart. In that case the target configuration has to name /var/lib/stalwart, and you run the tool with --target-path-map /var/lib/stalwart=/var/lib/stalwart-v1. That is what you passed, so check what /etc/stalwart-v1/config.json actually contains. If it still says /var/lib/stalwart-v1, either edit the path in it or use the first option.

The first option is the simpler fix. After changing the mount, docker compose up -d stalwart-v1 should be enough. You shouldn’t need to re-run the migration.

Docs: Installation | Stalwart (see “Mounting the new store in the 1.0 container” and “Paths and file ownership”).

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

The path map isn’t doing anything here. --target-path-map /var/lib/stalwart=/var/lib/stalwart-v1 only rewrites paths that start with /var/lib/stalwart in the target config, and the error shows that your /etc/stalwart-v1/config.json names /var/lib/stalwart-v1. So the tool wrote the store to /var/lib/stalwart-v1, v1 reads the same config and looks there, but your v1 container mounts the data volume at /var/lib/stalwart. Inside that container /var/lib/stalwart-v1 doesn’t exist, and the stalwart user isn’t allowed to create it.

Mounting the volume where the config points fixes it:

      volumes:
        - stalwart-v1-etc:/etc/stalwart
        - stalwart-v1-data:/var/lib/stalwart-v1

Make sure it’s the same Docker volume the migrate service wrote into. Compose prefixes volume names with the project name, so if v1 lives in a separate compose project, docker volume ls will show two different stalwart-v1-data volumes and you’ll want to declare the one with your data as external.

The other layout (data at /var/lib/stalwart in the v1 container, with the path map) is described here: Installation | Stalwart