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:
COPY 000-default.conf /tmp
COPY setuphttp.sh /opt
COPY ports.conf /tmp
RUN chmod 755 /opt/setuphttp.sh
4) Create the file ports.conf containing this
$ vi ports.conf
5) Finally the script setuphttp.sh containing the commands to run inside the container!
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/
mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
mkdir -p /run/httpd
chmod 777 /run/httpd
rm -f /var/run/apache2/apache2.pid
/usr/sbin/apache2ctl -D FOREGROUND
So, in our directory http we have those files:
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
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ca8703ec8049 web “/opt/setuphttp.sh” 3 months ago Up 5 days 0.0.0.0:8080->8080/tcp