March 21, 2017

Raspberry Pi 3: how to create http fileserver inside a Docker container

Posted in Raspberry at 9:08 pm by alessiodini

After a long time where I was incredible busy, I have a time to write a new post 🙂

On December I bought Raspberry Pi 3, and I’m still playing with it using some software I’m writing and docker containers.
One of my first goals was to create a public http fileserver where I could put iso files, job notes, scripts, and much more.
For this purpose I made one dedicated container, called “web”.
Following these instructions you can easily replicate my job having a web container running on port 8080:

1) Create a working directory called “http”.

$ mkdir http
$ cd http

2) Create all the files needed for the web image and later for the container

$ vi 000-default.conf

( you can get the file here )

3) Create a Dockerfile

$ vi Dockerfile

Put inside the Docker file:

FROM armhf/debian

COPY 000-default.conf /tmp

COPY /opt

COPY ports.conf /tmp

RUN chmod 755 /opt/

CMD ["/opt/"]

4) Create the file ports.conf containing this

$ vi ports.conf

5) Finally the script containing the commands to run inside the container!


apt-get update
apt-get install -y apache2 apache2-utils
echo "password_here" | htpasswd -i -c /etc/apache2/.htpasswd download ( this will be the user for the authentication )
cp -f /tmp/ports.conf /etc/apache2/
cp -f /tmp/000-default.conf /etc/apache2/sites-available/
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_LOG_DIR=/var/log/apache2
export APACHE_PID_FILE=/var/run/
export APACHE_RUN_DIR=/var/run/apache2
export APACHE_LOCK_DIR=/var/lock/apache2
mkdir -p /run/httpd
chmod 777 /run/httpd
rm -f /var/run/apache2/
/usr/sbin/apache2ctl -D FOREGROUND

So, in our directory http we have those files:
– 000-default.conf
– Dockerfile
– ports.conf

now the fun begins!
Let’s build the image called “web”:

$ docker build -t web .

Let’s suppose we have a directory called /http on our physical raspberry ( where we have all files we need to share via web ) we would like to share it to the container. How?

$ sudo docker run -d –privileged=true –name web -p 8080:8080 -v /http:/web web

What did I just run?

docker run -d -> run in background
–name web -> name of the container
-p 8080:8080 -> this is the port forwarding between the docker and the raspberry
-v /http:/web -> this mounts /http from the raspberry as /web inside the container
web -> the name of this container!

How can I check the container status?

$ docker ps -a
ca8703ec8049 web “/opt/” 3 months ago Up 5 days>8080/tcp



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: