Skip to content
Beau Barker edited this page Jul 19, 2025 · 7 revisions

Keys

Generate public and private keys for the host (use no passphrase):

mkdir -p keys/{host,user}
ssh-keygen -t ed25519 -f keys/host/ssh_host_ed25519_key < /dev/null
ssh-keygen -t rsa -b 4096 -f keys/host/ssh_host_rsa_key < /dev/null

Put your public user key(s) in keys/user.

Add the sftp service

Add an sftp service to compose.yaml:

sftp:
  image: atmoz/sftp
  command: user:pass:1001
  ports:
    - "2222:22"
  volumes:
    - ./keys/host/ssh_host_ed25519_key:/etc/ssh/ssh_host_ed25519_key:ro
    - ./keys/host/ssh_host_rsa_key:/etc/ssh/ssh_host_rsa_key:ro
    - ./keys/user:/home/user/.ssh/keys:ro
    - sftp_data:/home/user/upload:rw

And a volume:

volumes:
  sftp_data:

Caddy

Also add the sftp_data volume to the caddy service:

services:
  caddy:
    volumes:
      - sftp_data:/upload:ro

Add to the caddy/Caddyfile:

# Serve uploaded files
handle_path /upload/* {
  root * /upload
  file_server
  # Disable the 'Expect: 100-continue' header for easier uploads
  header Expect nil
  # Long-term caching for uploaded files
  header Cache-Control "public, max-age=2592000, immutable"
}

How to copy files to the volume

docker compose cp path/to/files/. sftp:/home/user/upload/
Clone this wiki locally