如何使用 Docker-Compose 部署 FTP 服务?
2018-11-06 by dongnan
目标
使用 docker-compose
,创建一个 ftp
服务。
环境
软件 | 版本 |
---|---|
docker-compose |
1.11.2 |
docker |
17.12.1-ce |
image |
fauria/vsftpd:latest |
配置文件
cat docker-compose.yml
version: '2'
services:
ftpd:
image: fauria/vsftpd
container_name: vsftpd
volumes:
- /etc/localtime:/etc/localtime:ro
- web-data:/home/vsftpd
- /var/log/vsftpd.log:/var/log/vsftpd.log
environment:
- TZ=Asia/Chongqing
- FTP_USER=dongnan
- FTP_PASS=zongming.net
- PASV_MIN_PORT=21100
- PASV_MAX_PORT=21200
ports:
- "20:20"
- "21:21"
- "21100-21200:21100-21200"
volumes:
web-data:
driver: local
重要配置项
FTP_USER/FTP_PASS
变量对应的是用户名与密码。PASV
FTP被动模式(passive mode)。- 映射端口 命令端口
TCP:21
,数据端口TCP:21100-21110
。
步骤
创建容器
docker-compose up -d
Starting vsftpd
容器日志
docker-compose logs --tail 5
Attaching to vsftpd
vsftpd | ---------------
vsftpd | · FTP User: dongnan
vsftpd | · FTP Password: zongming.net
vsftpd | · Log file: /var/log/vsftpd/vsftpd.log
vsftpd | · Redirect vsftpd log to STDOUT: No.
测试FTP
ftp 6.6.6.6
Connected to 6.6.6.6.
220 (vsFTPd 3.0.2)
Name (6.6.6.6:dongnan): dongnan
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
# 列出目录
ftp> dir
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
# 上传文件
ftp> put exam.txt
local: exam.txt remote: exam.txt
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
2177 bytes sent in 0.00 secs (70865.9 kB/s)
# 列出目录
ftp> dir
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw------- 1 ftp ftp 2177 Nov 05 08:25 exam.txt
226 Directory send OK.
# 下载文件
ftp> get exam.txt
local: exam.txt remote: exam.txt
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for exam.txt (2177 bytes).
226 Transfer complete.
2177 bytes received in 0.00 secs (1230.3 kB/s)
# 删除文件
ftp> delete exam.txt
250 Delete operation successful.
ftp> dir
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
# 退出
ftp> quit
221 Goodbye.
小结
使用 vsftp
镜像,借助 docker-compose
可以便捷的创建一个FTP
服务,需要注意的是Docker-Hub
没有找到VSFTP官方提供的镜像,使用第三方的镜像需要自行评估安全性问题。