Centos 7 docker ftp

拉取镜像

1
2
3
4
docker pull nginx

docker pull vsftpd

docker启动nginx容器,命名为test

nginx配置default.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
cat default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;

#access_log /var/log/nginx/host.access.log main;

location / {
root /mnt/data;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

nginx配置nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
cat nginx.conf

user root;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

docker启动nginx

1
2
3
4
5
6
7
8
9
docker run -d -p 80:80 \
--name nginx --net host \
-v /usr/docker/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/docker/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
-v /usr/docker/nginx/html:/usr/share/nginx/html \
-v /usr/docker/vsftpd:/mnt/data \
-v /usr/docker/nginx/logs:/var/log/nginx \
--privileged=true --restart=always nginx

docker启动vsftpd

1
2
3
4
5
6
7
docker run -d -v /root/docker/vsftpd:/home/vsftpd \
-p 20:20 -p 21:21 -p 21100-21110:21100-21110 \
-e FTP_USER=test -e FTP_PASS=testgs \
-e PASV_ADDRESS=104.225.145.216 \
-e PASV_MIN_PORT=21100 -e PASV_MAX_PORT=21110 \
--name vsftpd --restart=always fauria/vsftpd

秘诀在于 ftp的被映射出来的文件路径 /root/dockers/vsftpd:/home/vsftpd
刚好和nginx的 root /mnt/data映射出来的路径一致
访问nginx的root,就相当于访问了ftp的文件目录