Skip to content

Run in Docker

The image runs uFTP as the user uftp (uid 10001), not as root. A normal user cannot open port 21, so inside the container uFTP listens on 2121, and you map it to 21 outside.

The files are in the repository, in contrib/docker/: Dockerfile, a sample uftpd.cfg, docker-compose.yml and a README.md.

The image has TLS (OpenSSL) and IPv6, and is about 9 MB.

Build and run

From the root of the repository, build the image and prepare a private configuration for the first installation.

docker build -f contrib/docker/Dockerfile -t uftp .
mkdir -p "$HOME/.config/uftp"
export UFTP_DOCKER_CONFIG="$HOME/.config/uftp/uftpd.docker.cfg"
install -m 0600 contrib/docker/uftpd.cfg "$UFTP_DOCKER_CONFIG"
docker run --rm -it --entrypoint /usr/local/sbin/uFTP uftp --hash-password

Edit the file at $UFTP_DOCKER_CONFIG. Enable the three account lines and set PASSWORD_0 to the generated hash. Give the container read access to the file before publishing the ports.

sudo chgrp 10001 "$UFTP_DOCKER_CONFIG"
chmod 0640 "$UFTP_DOCKER_CONFIG"
mkdir -p ftp-data tls
sudo chown 10001:10001 ftp-data tls
docker run -d --name uftp -p 21:2121 -p 40000-40100:40000-40100 \
  -v "$PWD/ftp-data:/srv/ftp" -v "$PWD/tls:/etc/uftp/tls" \
  --mount "type=bind,src=$UFTP_DOCKER_CONFIG,dst=/etc/uftp/uftpd.cfg,readonly" \
  uftp

The certificate

A build with TLS needs a certificate to start. If /etc/uftp/tls has no cert.pem and key.pem, the image makes a self-signed one at the first start and says so on the container log: FTPS works, but clients will not trust it. Mount the folder tls as above to keep that certificate across restarts, or to put your own cert.pem and key.pem there (readable by uid 10001, see TLS and certificates). With a read-only disk and no mounted folder the container stops and says why.

Passive FTP

FTP opens a second connection for every transfer. In the container:

  1. Publish the same port numbers on the host as the passive range of the configuration (RANDOM_PORT_START and RANDOM_PORT_END): -p 40000-40100:40000-40100. The server tells the client the port it listens on, so the numbers must be equal on both sides.
  2. Set SERVER_IP to the address of the host as the client sees it, with commas (SERVER_IP = 192,0,2,10): the container only knows its private address.

More in Behind a NAT or a firewall.

Your own configuration

The file at $UFTP_DOCKER_CONFIG is mounted at /etc/uftp/uftpd.cfg. Use paths inside the container for HOME_n, CERTIFICATE_PATH and PRIVATE_CERTIFICATE_PATH. The home and certificate files must be accessible to uid 10001. Configuration ยท TLS and certificates

Share folders of the host

uFTP in the container only sees what you mount. Mount each folder you want to share with -v <folder of the host>:<folder in the container>, then point HOME_n of each user at a folder inside the container. Example: two shared folders of the host, three users.

docker run -d --name uftp -p 21:2121 -p 40000-40100:40000-40100 \
  -v /home/you/documents:/srv/ftp/documents \
  -v /home/you/incoming:/srv/ftp/incoming \
  -v /home/you/photos:/srv/ftp/photos:ro \
  -v "$PWD/tls:/etc/uftp/tls" \
  --mount "type=bind,src=$UFTP_DOCKER_CONFIG,dst=/etc/uftp/uftpd.cfg,readonly" \
  uftp
# uftpd.cfg (the paths are the ones of the container)
# Full access to the documents.
USER_0 = you
PASSWORD_0 = $pbkdf2-sha256$...
HOME_0 = /srv/ftp/documents/

# Read-only access to the photos.
USER_1 = family
PASSWORD_1 = $pbkdf2-sha256$...
HOME_1 = /srv/ftp/photos/
READ_ONLY_1 = true
MAX_DOWNLOAD_SPEED_1 = 2048           # 2 MB/s

# Upload access to the drop box.
USER_2 = clients
PASSWORD_2 = $pbkdf2-sha256$...
HOME_2 = /srv/ftp/incoming/
PERMISSIONS_2 = upload,mkdir
MAX_UPLOAD_SPEED_2 = 1024             # 1 MB/s

Three things to know:

  • Who owns the files. The server in the container is the user uftp (uid 10001), so on the host the folder must let that uid write, or the uploads fail with 550. Either give it the folder, sudo chown -R 10001:10001 /home/you/incoming, or, to keep your own owner, add an ACL: sudo setfacl -R -m u:10001:rwX /home/you/incoming (and -d -m for the files created later). New files belong to uid 10001 on the host.
  • Read only is two locks, use both for what must not change. :ro on the mount makes the folder read-only for the whole container (the server gets an error if it tries to write); READ_ONLY_n = true or PERMISSIONS_n limits what each user may do, and gives a clear 550 Permission denied instead of a write error. See Configuration.
  • Do not mount / or system folders (/etc, /home, /var) as the home of a user: a user can read and write all that the server can. Mount the folders you want to share, nothing else.

The users can also live in a file of their own, so the configuration has no passwords: put USERS_FILE = /etc/uftp/users.cfg in uftpd.cfg and mount the file (-v "$PWD/users.cfg:/etc/uftp/users.cfg:ro", readable by uid 10001). To make it from the users you have: uFTP --split-users (see Configuration).

Docker Compose

docker-compose.yml does the same, and also makes the container stricter: a read-only disk (the log folder is a tmpfs, the certificate folder is mounted), no capability, and no new privileges. The image has been run with exactly these restrictions: FTP and FTPS logins, uploads and downloads work, and the files belong to the user uftp.

Run these commands from the repository root after preparing and exporting UFTP_DOCKER_CONFIG as above. Compose uses data and certificate directories next to its YAML file.

mkdir -p contrib/docker/ftp-data contrib/docker/tls
sudo chown 10001:10001 contrib/docker/ftp-data contrib/docker/tls
docker compose -f contrib/docker/docker-compose.yml up -d

To share folders add them under volumes:, as in the example above:

    volumes:
      - /home/you/documents:/srv/ftp/documents
      - /home/you/incoming:/srv/ftp/incoming
      - /home/you/photos:/srv/ftp/photos:ro

Stopping

The image starts uFTP under tini, a small init process: as process 1 of a container, uFTP would ignore SIGTERM and docker stop would wait ten seconds and kill it. With tini it stops at once if no transfer is going on; otherwise uFTP lets the transfers in progress end, up to SHUTDOWN_GRACE_SECONDS (30 s by default, see Configuration). docker stop waits only 10 seconds before it kills the container: use docker stop -t 40 or, in Compose, stop_grace_period: 40s.

A big published port range makes docker stop slower. The passive range of the example is 40000-40100 (101 ports): Docker takes about 6 seconds to remove them after the container has already exited (measured: uFTP itself exits 0.2 s after the last transfer ends). If that matters, publish fewer ports (RANDOM_PORT_START/RANDOM_PORT_END of 10 to 20 ports are enough for a small server) and the same on the host.

What does not work without root

Logging in system users with PAM, and giving new files to another owner (USER_NAME_OWNER_n): the log says so at startup. After a change of the rest of the configuration restart the container. The TLS certificate and the users are read again without a restart: docker kill -s HUP uftp.

Health

The image has a HEALTHCHECK that asks /livez inside the container; /readyz and /metrics are there too, on port 8080 of the container only. See Watch the server.