A simple FTP server, using
vsftpd.
The build runs apk upgrade, so Alpine package fixes reach the image with the
next build even before a new Alpine point release.
| Variable | Default | Effect |
|---|---|---|
FTP_USER | foo | Name of the one account. |
FTP_PASS | bar | Its password. |
UID | 1000 | Numeric user id of the account. |
GID | 1000 | Numeric group id of the account. |
FTP_ROOT | /home/$FTP_USER | The directory the account is confined to. |
PASV_ADDRESS | — | Address the server advertises in passive mode. |
FTP_ROOT is the chroot root: the client lands there, sees it as / and
cannot leave it. The entrypoint creates the directory and makes the account
its owner, but does not touch what lies inside it, so a mount point full of
another service's files keeps its ownership. A literal $USER in the value
is substituted with the account name, so FTP_ROOT='/srv/$USER' gives one
directory per account.
PASV_ADDRESS has to be set to an address the client can reach, otherwise
the server advertises its own container address in passive mode and no data
connection comes about. There is no sensible default for it: only the
operator knows which address a client sees.
To start a container, with data stored in /data on the host, use the
following. PASV_ADDRESS is the address of the host the clients connect to,
and /home/user is where the account is confined to, so the volume belongs
there:
docker run \
--detach \
--env FTP_PASS=123 \
--env FTP_USER=user \
--env PASV_ADDRESS=203.0.113.7 \
--name my-ftp-server \
--publish 20-21:20-21/tcp \
--publish 40000-40009:40000-40009/tcp \
--volume /data:/home/user \
ricariel/ftp-server
docker composeservices:
ftp-server:
container_name: my-ftp-server
environment:
- FTP_PASS=123
- FTP_USER=user
- PASV_ADDRESS=203.0.113.7
image: ricariel/ftp-server
ports:
- '20-21:20-21/tcp'
- '40000-40009:40000-40009/tcp'
volumes:
- '/data:/home/user'
tests/ holds behaviour tests for this image, run by pytest in a throw-away
container. Which suites exist, which paths affect them and which test a change
has to touch is recorded in tests/suites.yaml; the CI starts only the suites
a pull request affects.
smoke covers that the container comes up, greets on port 21, lets the
configured account in and refuses a wrong password, an unknown account and an
anonymous login; that the exposed ports cover the passive range; and that a
refused login does not take the daemon with it.
access covers the round trip over the data channel (upload, list, download,
compare, delete), a LIST over a data connection, the advertised passive
address and its counter case without PASV_ADDRESS, the chroot (an absolute
path and a .. traversal stay inside the root, nothing above it is
reachable), the umask of an upload and the hidden account names in a listing.
entrypoint covers what UID, GID, FTP_PASS, FTP_ROOT and
PASV_ADDRESS make of the account and the configuration, that the root is
claimed without rewriting what lies in it, that both log files reach the
container log, and that a new container on the same volume keeps the files
with their owner and permissions.
Every case speaks FTP with ftplib against a published port instead of asking
the server from the inside. The reason is the data channel: in passive mode the
server names an address and a port, and whether a client outside the container
reaches them is what this image lives or dies by. The account is generated per
run and masked out of every output, so no credential of a test ends up in the
CI log.
The passive range cannot be chosen freely, because the client connects to the
port number the server names: the tests read pasv_min_port and pasv_max_port
out of src/vsftpd.conf and publish that range one to one. A container
therefore waits when a suite running at the same time still holds it.
Run them like the CI does, one suite at a time:
./tests/run.sh smoke
./tests/run.sh access
./tests/run.sh entrypoint
IMAGE=docker-ftp-server:latest ./tests/run.sh access # tests an existing image
Without IMAGE each run builds the image itself, which is what the counter
check needs: corrupt something in Dockerfile or src/, and the suite that
covers it has to turn red.
Content type
Image
Digest
sha256:a0b22dda6…
Size
6.5 MB
Last updated
about 8 hours ago
docker pull ricariel/ftp-server