Play Raspberry Pi(7)FTP in Docker

Play Raspberry Pi(7)FTP in Docker

1 Set up PureFTPD in Ubuntu

PureFTPD on ubuntu
http://www.jianshu.com/p/fa037a4866e6
http://i.linuxtoy.org/docs/guide/ch23s05.html
http://wiki.ubuntu.org.cn/Pure-ftpd%E6%9C%8D%E5%8A%A1%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE

http://4408149.blog.51cto.com/4398149/1735815

Install command
> sudo apt-get install pure-ftpd

Create group
> sudo groupadd ftpgroup

Create user
> sudo useradd -g ftpgroup -d /var/ftp/sillycat -s /bin/bash sillycat

Create Virtual User
> sudo pure-pw useradd sillycat -u sillycat -g ftpgroup -d /var/ftp/sillycat

first sillycat is virtual user
second sillycat is the system user, lock the user in the directory.

Create virtual user data
> sudo pure-pw mkdb

Soft link the user db to auth directory
> sudo ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb

Restart the server
> sudo /etc/init.d/pure-ftpd restart
Restarting ftp server: Running: /usr/sbin/pure-ftpd -l puredb:/etc/pure-ftpd/pureftpd.pdb -l pam -8 UTF-8 -u 1000 -J ALL:!aNULL:!SSLv3 -O clf:/var/log/pure-ftpd/transfer.log -E -B

Permission
> sudo chmod -R 777 /var/ftp

Verify the installation
http://sillycat.iteye.com/blog/2255064

> sudo apt-get install ftp

> ftp localhost 21

ftp> put README.md

2 Set up PureFTPD in Docker on Ubuntu
Check docker version
> docker version
Client:
Version:      1.11.2
API version:  1.23
Go version:   go1.5.4
Git commit:   b9f10c9
Built:        Wed Jun  1 21:47:50 2016
OS/Arch:      linux/amd64

Server:
Version:      1.11.2
API version:  1.23
Go version:   go1.5.4
Git commit:   b9f10c9
Built:        Wed Jun  1 21:47:50 2016
OS/Arch:      linux/amd64

All similar to non docker, the docker file is as follow:
> cat Dockerfile
#Set up FTP in Docker

#Prepre the OS
FROM ubuntu:14.04
MAINTAINER Carl Luo <[email protected]>

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -qq update
RUN apt-get -qqy dist-upgrade

#Install the tools
RUN apt-get -qqy install pure-ftpd

#set up config and users
RUN mkdir -p /var/ftp
RUN chmod -R 777 /var/ftp
RUN groupadd ftpgroup
RUN useradd luohuazju
RUN { echo kaishi; echo kaishi; } | passwd luohuazju
RUN { echo kaishi; echo kaishi; } | pure-pw useradd luohuazju -u luohuazju -g ftpgroup -d /var/ftp/luohuazju
RUN pure-pw mkdb
RUN ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb

#start the application
EXPOSE  21
RUN     mkdir -p /app/
ADD     start.sh /app/
WORKDIR /app/
CMD [ "./start.sh" ]

> cat Makefile
IMAGE=sillycat/public
TAG=ubuntu-pureftpd
NAME=ubuntu-pureftpd

docker-context:

build: docker-context
# docker build --no-cache -t $(IMAGE):$(TAG) .
docker build -t $(IMAGE):$(TAG) .

run:
docker run -d -p 21:21 -p 30000-30009:30000-30009 -v $(shell pwd)/ftp:/var/ftp --name $(NAME) $(IMAGE):$(TAG)

debug:
docker run -ti -p 21:21 -p 30000-30009:30000-30009 -v $(shell pwd)/ftp:/var/ftp --name $(NAME) $(IMAGE):$(TAG) /bin/bash

clean:
docker stop ${NAME}
docker rm ${NAME}

logs:
docker logs ${NAME}

publish:
docker push ${IMAGE}


> cat start.sh
#!/bin/sh -ex

#start the ftp
/etc/init.d/pure-ftpd restart
#tail the logging
tail -f /dev/null

Exception:
421 Unable to switch capabilities : Operation not permitted

Solution:
I am running that in one virtual ubuntu system. I will directly run that in my CentOS or RaspberryPi.
It works on CentOS.

3 PureFTP runs on RaspberryPi
> docker version
Client:
Version:      1.10.3
API version:  1.22
Go version:   go1.4.3
Git commit:   20f81dd
Built:        Thu Mar 10 22:23:48 2016
OS/Arch:      linux/arm

Server:
Version:      1.10.3
API version:  1.22
Go version:   go1.4.3
Git commit:   20f81dd
Built:        Thu Mar 10 22:23:48 2016
OS/Arch:      linux/arm

All the configurations are the same for RaspberryPi

I was doing the things on and external USB hard driver through NTFS.
I get issues when I run the docker application
Error Message:
docker: Error response from daemon: error creating overlay mount to /mnt/driver1/data/docker/overlay/2a1f2702b7538a9ea5e070bd708e7f97c0df255fb76d73b48b2543f5c5fb40e1-init/merged: invalid argument.
See 'docker run --help'.
Makefile:12: recipe for target 'run' failed
make: *** [run] Error 125

Error Message:
exec format error
Cannot start container 78e7cf21e232f36a387b28cb6b5b5421a922b553ef56271f911f24fd45c8b473: [9] System error: exec format error

Solution:
Do NOT use USB Driver to store docker images. Only configure the tmp directory to USB
> cat /etc/default/docker
# Docker Upstart and SysVinit configuration file

# This is also a handy place to tweak where Docker's temporary files go.
export TMPDIR="/opt/docker/tmp"

> docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 3
Server Version: 1.10.3
Storage Driver: overlay
Backing Filesystem: extfs

The Dockerfile need to be changed, it is not right to run things like that directly on raspberryPI arm system.
#Prepre the OS
#FROM ubuntu:14.04
FROM resin/rpi-raspbian:jessie

Exception:
421 Unable to switch capabilities : Operation not permitted

Solution:
http://dikant.de/2009/01/22/setting-up-pureftpd-on-a-virtual-server/

https://github.com/stilliard/docker-pure-ftpd/blob/master/Dockerfile
We need build the PureFTP ourselves with options.
https://hub.docker.com/r/stilliard/pure-ftpd/~/dockerfile/

> cat Dockerfile
#Set up FTP in Docker

#Prepre the OS
FROM resin/rpi-raspbian:jessie
MAINTAINER Carl Luo <[email protected]>

ENV DEBIAN_FRONTEND noninteractive
RUN echo "deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi\n\
deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi\n\
" > /etc/apt/sources.list
RUN apt-get -y update
RUN apt-get -y dist-upgrade
RUN apt-get -y --force-yes install dpkg-dev debhelper

#Install the tools
RUN apt-get -y build-dep pure-ftpd
RUN mkdir /tmp/pure-ftpd/ && \
cd /tmp/pure-ftpd/ && \
apt-get source pure-ftpd && \
cd pure-ftpd-* && \
sed -i '/^optflags=/ s/$/ --without-capabilities/g' ./debian/rules && \
dpkg-buildpackage -b -uc
RUN dpkg -i /tmp/pure-ftpd/pure-ftpd-common*.deb
RUN apt-get -y install openbsd-inetd
RUN dpkg -i /tmp/pure-ftpd/pure-ftpd_*.deb

# Prevent pure-ftpd upgrading
RUN apt-mark hold pure-ftpd pure-ftpd-common

#set up config and users
RUN echo 'yes' > /etc/pure-ftpd/conf/VerboseLog
RUN mkdir -p /var/ftp/xxxx1
RUN mkdir -p /var/ftp/xxxx2
RUN chmod -R 777 /var/ftp
RUN groupadd ftpgroup
RUN useradd xxxx1
RUN useradd xxxx2
RUN { echo aaaa1; echo aaaa1; } | passwd xxxx1
RUN { echo aaaa2; echo aaaa2; } | passwd xxxx2
RUN { echo aaaa1; echo aaaa1; } | pure-pw useradd xxxx1 -u xxxx1 -g ftpgroup -d /var/ftp/xxxx1
RUN { echo aaaa2; echo aaaa2; } | pure-pw useradd xxxx2 -u xxxx2 -g ftpgroup -d /var/ftp/xxxx2
RUN pure-pw mkdb
RUN ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb

#start the application
EXPOSE  21 30000-30009
RUN     mkdir -p /app/
ADD     start.sh /app/
WORKDIR /app/
CMD [ "./start.sh" ]

> cat start.sh
#!/bin/sh -ex

#start the ftp
/etc/init.d/pure-ftpd restart
#tail the logging
tail -f /dev/null

> cat Makefile
IMAGE=sillycat/public
TAG=ubuntu-pureftpd
NAME=ubuntu-pureftpd

docker-context:

build: docker-context
# docker build --no-cache -t $(IMAGE):$(TAG) .
docker build -t $(IMAGE):$(TAG) .

run:
docker run -d -p 21:21 -p 30000-30009:30000-30009 -v $(shell pwd)/ftp:/var/ftp --name $(NAME) $(IMAGE):$(TAG)

debug:
docker run -ti -p 21:21 -p 30000-30009:30000-30009 -v $(shell pwd)/ftp:/var/ftp --name $(NAME) $(IMAGE):$(TAG) /bin/bash

clean:
docker stop ${NAME}
docker rm ${NAME}

logs:
docker logs ${NAME}

publish:
docker push ${IMAGE}:${TAG}

fetch:
docker pull ${IMAGE}:${TAG}


That is done. It is running great there.
> docker ps
CONTAINER ID        IMAGE                             COMMAND             CREATED             STATUS              PORTS                                                      NAMES
c7bed6579780        sillycat/public:ubuntu-pureftpd   "./start.sh"        2 days ago          Up 2 days           0.0.0.0:21->21/tcp, 0.0.0.0:30000-30009->30000-30009/tcp   ubuntu-pureftpd

And when we are using FileZilla, make sure we are setting Transfer Settings to “Active”.

References:
PureFTPD
https://github.com/stilliard/docker-pure-ftpd/blob/master/Dockerfile

https://www.pureftpd.org/project/pure-ftpd/download
http://stackoverflow.com/questions/23930167/installing-pure-ftpd-in-docker-debian-wheezy-error-421
http://wiki.ubuntu.org.cn/Pure-ftpd%E6%9C%8D%E5%8A%A1%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE

One Java FTP
http://sillycat.iteye.com/blog/2255064

猜你喜欢

转载自sillycat.iteye.com/blog/2306242