云原生之使用Docker部署ftp服务器
【摘要】 云原生之使用Docker部署ftp服务器
一、ftp介绍
ftp分为主动模式(PORT)和被动模式(PASV)。主动模式使用20和21端口,其中20为数据端口,21为控制端口。被动模式使用21控制端口和一个其他随机端口作数据端口。
二、检查本地docker状态
[root@node ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-10-28 13:19:21 CST; 10h ago
Docs: https://docs.docker.com
Main PID: 76667 (dockerd)
Tasks: 26
Memory: 1.5G
CGroup: /system.slice/docker.service
├─ 76667 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─113263 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.20.0.4 -container-port 8080
└─113272 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8080 -container-ip 172.20.0.4 -container-port 8080
Oct 28 18:20:58 node dockerd[76667]: time="2022-10-28T18:20:58.288655357+08:00" level=info msg="Container failed to exit within 10s of s...d72e076f
Oct 28 18:20:58 node dockerd[76667]: time="2022-10-28T18:20:58.332958782+08:00" level=info msg="ignoring event" container=9d5d9e1f2a9e27...kDelete"
Oct 28 18:34:37 node dockerd[76667]: time="2022-10-28T18:34:37.034425164+08:00" level=info msg="Container failed to exit within 10s of s...d72e076f
Oct 28 18:34:37 node dockerd[76667]: time="2022-10-28T18:34:37.076085196+08:00" level=info msg="ignoring event" container=9d5d9e1f2a9e27...kDelete"
Oct 28 18:49:20 node dockerd[76667]: time="2022-10-28T18:49:20.711383881+08:00" level=info msg="Container failed to exit within 10s of s...d72e076f
Oct 28 18:49:20 node dockerd[76667]: time="2022-10-28T18:49:20.762906859+08:00" level=info msg="ignoring event" container=9d5d9e1f2a9e27...kDelete"
Oct 28 18:51:31 node dockerd[76667]: time="2022-10-28T18:51:31.734729814+08:00" level=info msg="Container failed to exit within 10s of s...d72e076f
Oct 28 18:51:31 node dockerd[76667]: time="2022-10-28T18:51:31.776846324+08:00" level=info msg="ignoring event" container=9d5d9e1f2a9e27...kDelete"
Oct 28 18:51:32 node dockerd[76667]: time="2022-10-28T18:51:32.051543900+08:00" level=info msg="ignoring event" container=b9940db8d7817f...kDelete"
Oct 28 18:51:32 node dockerd[76667]: time="2022-10-28T18:51:32.235131874+08:00" level=info msg="ignoring event" container=826cd78a351542...kDelete"
Hint: Some lines were ellipsized, use -l to show in full.
三、下载vsftpd镜像
[root@node ~]# docker pull fauria/vsftpd
Using default tag: latest
latest: Pulling from fauria/vsftpd
75f829a71a1c: Pull complete
a1a6b490d7c7: Pull complete
ad2cabfec967: Pull complete
c7a98e8d62f5: Pull complete
10d192add873: Pull complete
fc18a09c86d0: Pull complete
5397e9c5e314: Pull complete
e89f582c70f5: Pull complete
8b8bdebbfc97: Pull complete
026ae919720d: Pull complete
Digest: sha256:c3988c1b8418018a05688a0553986d87aa7c72a293ad7e74467972c1aad3d6b7
Status: Downloaded newer image for fauria/vsftpd:latest
docker.io/fauria/vsftpd:latest
四、创建vsftpd容器
1.创建数据目录
[root@node ~]# mkdir -p /data/ftp/data && mkdir -p /data/ftp/log && chmod -R 777 /data/ftp
2.创建vsftpd容器
docker run -d \
--name vsftpd \
--restart=always \
-v /data/ftp/data/:/home/vsftpd \
-v /data/ftp/log/:/var/log/vsftpd/ \
-p 20:20 -p 21:21 -p 20000:20000 \
-e FTP_USER=admin \
-e FTP_PASS=admin \
-e PASV_MIN_PORT=20000 \
-e PASV_MAX_PORT=20000 \
-e PASV_ADDRESS=192.168.3.166 \
-e LOG_STDOUT=1 \
fauria/vsftpd
3.查看vsftpd容器状态
[root@node ftp]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fce7b8fc2279 fauria/vsftpd "/usr/sbin/run-vsftp…" 38 seconds ago Up 36 seconds 0.0.0.0:20-21->20-21/tcp, :::20-21->20-21/tcp, 0.0.0.0:20000->20000/tcp, :::20000->20000/tcp vsftpd
五、linux客户端访问ftp
1.安装ftp客户端软件
yum install -y ftp
2.登录ftp
[root@node ftp]# ftp 192.168.3.166
Connected to 192.168.3.166 (192.168.3.166).
220 (vsFTPd 3.0.2)
Name (192.168.3.166:root): admin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,3,166,78,32).
150 Here comes the directory listing.
226 Directory send OK.
ftp>
六、web页面访问ftp
七、上传文件
1.在挂载数据目录上传文件
[root@node admin]# mkdir test it linux
[root@node admin]#
[root@node admin]# ls
it linux test
[root@node admin]# cd linux/
[root@node linux]# touch file100
2.查看ftp上文件
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)