美文网首页Docker容器
vsftp-ubuntu-docker学习实践

vsftp-ubuntu-docker学习实践

作者: Shark1985 | 来源:发表于2019-06-13 15:05 被阅读1次

    dockerfile

    #source image 
    FROM ubuntu:xenial 
    
    #Author 
    MAINTAINER shark1985 
    
    #Add file 
    ADD sources.list /tmp 
    
    #Sources.list 
    RUN mv /etc/apt/sources.list /etc/apt/source.list.bak && cp /tmp/sources.list /etc/apt/ 
    
    #Apt update&install 
    RUN apt-get update && apt-get install -y vsftpd 
    
    #Add ftp dir 
    RUN cd /srv/ftp && mkdir anyone && chmod 777 anyone && chown ftp:ftp anyone && mkdir -p /var/run/vsftpd/empty 
    
    #Dir mount 
    VOLUME /src/ftp/anyone 
    
    #Backup config 
    RUN mv /etc/vsftpd.conf /etc/vsftpd.conf.bak 
    
    #Config 
    ADD vsftpd.conf /etc/ 
    
    #Port 
    EXPOSE 21 20 
    
    #Service 
    CMD ["vsftpd"]
    

    匿名配置说明

    #匿名主目录 
    /srv/ftp 
    #匿名目录下创建新目录,并赋予777权限 
    mkdir anyone
    chmod 777 anyone 
    chown ftp:ftp anyone 
    ls -l 
    drwxrwxrwx 2 ftp ftp 4096 Jun 6 09:58 anyone
    

    vsftpd.conf

    anonymous_enable=YES
    write_enable=YES
    anon_upload_enable=YES
    anon_mkdir_write_enable=YES
    secure_chroot_dir=/var/run/vsftpd/empty
    

    构建过程

    Sending build context to Docker daemon   5.12kB
    Step 1/11 : FROM ubuntu:xenial
     ---> 2a697363a870
    Step 2/11 : MAINTAINER shark1985
     ---> Using cache
     ---> d40e95ba4a68
    Step 3/11 : ADD sources.list /tmp
     ---> Using cache
     ---> 72ae5928bef7
    Step 4/11 : RUN mv /etc/apt/sources.list /etc/apt/source.list.bak && cp /tmp/sources.list /etc/apt/
     ---> Using cache
     ---> facfcffd5888
    Step 5/11 : RUN apt-get update &&  apt-get install -y vsftpd
     ---> Using cache
     ---> 25a453daa0fe
    Step 6/11 : RUN cd /srv/ftp && mkdir anyone && chmod 777 anyone && chown ftp:ftp anyone && mkdir -p /var/run/vsftpd/empty
     ---> Using cache
     ---> 5166110341c1
    Step 7/11 : VOLUME /src/ftp/anyone
     ---> Using cache
     ---> 393dc302dd19
    Step 8/11 : RUN mv /etc/vsftpd.conf /etc/vsftpd.conf.bak
     ---> Using cache
     ---> f4bbe06e3e41
    Step 9/11 : ADD vsftpd.conf /etc/
     ---> 5e27b4c5ceef
    Step 10/11 : EXPOSE 21 20
     ---> Running in 96c696a2862f
    Removing intermediate container 96c696a2862f
     ---> 0f0ca16b178c
    Step 11/11 : CMD ["vsftpd"]
     ---> Running in c060af0a625e
    Removing intermediate container c060af0a625e
     ---> 85490c4228f8
    Successfully built 85490c4228f8
    Successfully tagged vsftp:latest
    

    运行

    docker run -d -p 21:21 -p 20:20 vsftp:latest
    c3f236aa083cd058121bf0fac9e947a4fdca3c22b546082be5ccfbc73bbd3fb0
    
    docker ps -a |grep vsftp
    17e70fb327f5        vsftp:latest                 "vsftpd"                 5 minutes ago       Up 5 minutes                0.0.0.0:20-21->20-21/tcp                       eager_meitner
    

    测试匿名登录成功

    Connecting to 10.x.x.x:21...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    220 (vsFTPd 3.0.2)
    Name (10.4.33.15:focus): ftp
    331 Please specify the password.
    Password: 
    230 Login successful.
    ftp:/> dir
    227 Entering Passive Mode (172,17,0,9,94,13).
    ftp:/> passive
    Passive mode off.
    ftp:/> dir
    200 PORT command successful. Consider using PASV.
    150 Here comes the directory listing.
    drwxrwxrwx    2 105      106          4096 Jun 10 09:26 anyone
    226 Directory send OK.
    ftp:/> cd anyone
    250 Directory successfully changed.
    ftp:/anyone> ls
    200 PORT command successful. Consider using PASV.
    150 Here comes the directory listing.
    226 Directory send OK.
    ftp:/anyone> put
    (local-file) grafana.md
    200 PORT command successful. Consider using PASV.
    150 Ok to send data.
    grafana.md: 2.52 KB sent in 0.001 sec (2,583 bytes, 2.46 MB/sec).
    226 Transfer complete.
    ftp:/anyone> ls
    200 PORT command successful. Consider using PASV.
    150 Here comes the directory listing.
    grafana.md
    

    存在的问题 : 实际ftp上传的文件应该保存到匿名卷目录对应的本地目录/var/lib/docker/volumes/下,但却保存到了/var/lib/docker/overlay2/,不知道是什么原因?

    匿名卷目录

    docker inspect 17e70fb327f5 |grep volume
                    "Type": "volume",
                    "Source": "/var/lib/docker/volumes/4baab887ff82658631586560849133d0da18529bb9d0ddf28e72045094651ce5/_data",
    

    ftp主目录实际对应的本地主机目录

    /var/lib/docker/overlay2/981b6e106d43605a64b5ade84cad92e2afab75335173cfaea4235c3c625e7013/diff/srv/ftp/anyone
    
    /var/lib/docker/overlay2/981b6e106d43605a64b5ade84cad92e2afab75335173cfaea4235c3c625e7013/merged/srv/ftp/anyone
    

    相关实际数据目录

            "GraphDriver": {
                "Data": {
                    "LowerDir": "/var/lib/docker/overlay2/981b6e106d43605a64b5ade84cad92e2afab75335173cfaea4235c3c625e7013-init/diff:/var/lib/docker/overlay2/86f37229743e751686d04f3f9b8062329cdacfa2c35d95dd8db756654e97f688/diff:/var/lib/docker/overlay2/3f4f4971cb774b36a5a40d7ec1c0c2e6f26b02459dc142857353dda25614ff33/diff:/var/lib/docker/overlay2/949e229978fe53716f46e663f62acfe8b853b61e695c9d788c63ece9bca9d33e/diff:/var/lib/docker/overlay2/607b909c4d9c11730b7b779d1b44159ac57b4e6f7c1725eb794bac2f7d9763f9/diff:/var/lib/docker/overlay2/ae1b0704bdadb6aede8e1a6b2dde4ec9125217a030a5edbfcb7c257df2bd3a91/diff:/var/lib/docker/overlay2/feca6313970fa2b12b1cade99da5162f0df1b7aeede8c0ed89b37d30cb0ffacf/diff:/var/lib/docker/overlay2/e6abfff5be32b3e5f5bc2fda933d2af3823cda251db33df7d5e7b58a27386082/diff:/var/lib/docker/overlay2/c640057e0fb98bf5d2132331b5b906294f1d3a51493d9d5ea0334797d493c29d/diff:/var/lib/docker/overlay2/a456d5880106522cbec836d763ce5ce35bc2bdbfa75f4c377d4d4a138a80f3cd/diff:/var/lib/docker/overlay2/796a45082b5f5264482fc613c9188c7dfb2040eedd45545991984c55708872a3/diff",
                    "MergedDir": "/var/lib/docker/overlay2/981b6e106d43605a64b5ade84cad92e2afab75335173cfaea4235c3c625e7013/merged",
                    "UpperDir": "/var/lib/docker/overlay2/981b6e106d43605a64b5ade84cad92e2afab75335173cfaea4235c3c625e7013/diff",
                    "WorkDir": "/var/lib/docker/overlay2/981b6e106d43605a64b5ade84cad92e2afab75335173cfaea4235c3c625e7013/work"
                },
                "Name": "overlay2"
            },
            "Mounts": [
                {
                    "Type": "volume",
                    "Name": "4baab887ff82658631586560849133d0da18529bb9d0ddf28e72045094651ce5",
                    "Source": "/var/lib/docker/volumes/4baab887ff82658631586560849133d0da18529bb9d0ddf28e72045094651ce5/_data",
                    "Destination": "/src/ftp/anyone",
                    "Driver": "local",
                    "Mode": "",
                    "RW": true,
                    "Propagation": ""
                }
            ]
    

    相关文章

      网友评论

        本文标题:vsftp-ubuntu-docker学习实践

        本文链接:https://www.haomeiwen.com/subject/nersfctx.html